-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-match-statementPython 3.10's match statementPython 3.10's match statementtopic-reachabilityDetecting unreachable codeDetecting unreachable code
Description
Can someone reopen this bug? There's a valid repro.
@cdce8p you're correct aboutstr, but can you reopen this bug? There’s another repro of this "Alternative patterns bind different names" bug that seems to be new in 1.18 (before it was silently Any).d1: dict[str, tuple[str, ...]] = {} d2: dict[str, str] = {} match (d1, d2): case ({"Symbol": (sym,)}, _) | (_, {"Symbol": sym}): reveal_type(sym)
# main.py:5: error: Alternative patterns bind different names [misc]I added a breakpoint to the source.
This looks like an issue in checkpattern.visit_or_pattern.
Debugging shows one alternative is givenNeverinstead of a tuple type::mypy/mypy/checkpattern.py(187)visit_or_pattern() -> self.msg.fail(message_registry.OR_PATTERN_ALTERNATIVE_NAMES, o.patterns[i]) (Pdb) p pattern_types[0] PatternType(type=tuple[builtins.dict[builtins.str, tuple[builtins.str]], builtins.dict[builtins.str, builtins.str]], rest_type=tuple[builtins.dict[builtins.str, tuple[builtins.str]], Never], captures={<mypy.nodes.NameExpr object at 0x7f50c2c2b9a0>: builtins.str}) (Pdb) p pattern_types[1] PatternType(type=Never, rest_type=tuple[Never, Never], captures={})So mypy concludes the alternatives bind differently, even though both capture sym.
Originally posted by @Hnasar in #13950
cc @cdce8p
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-match-statementPython 3.10's match statementPython 3.10's match statementtopic-reachabilityDetecting unreachable codeDetecting unreachable code