Skip to content

Commit 9f41000

Browse files
committed
Remove isinstance(Var) check: we want to exclude all clashing names
1 parent f87d9e5 commit 9f41000

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

mypy/checker.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5434,9 +5434,7 @@ def remove_capture_conflicts(
54345434
for expr, typ in list(type_map.items()):
54355435
if isinstance(expr, NameExpr):
54365436
node = expr.node
5437-
if isinstance(node, Var) and (
5438-
node not in inferred_types or not is_subtype(typ, inferred_types[node])
5439-
):
5437+
if node not in inferred_types or not is_subtype(typ, inferred_types[node]):
54405438
del type_map[expr]
54415439

54425440
def visit_type_alias_stmt(self, o: TypeAliasStmt) -> None:

test-data/unit/check-python310.test

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2448,7 +2448,7 @@ def x() -> tuple[Literal["test"]]: ...
24482448

24492449
match x():
24502450
case (x,) if x == "test": # E: Incompatible types in capture pattern (pattern captures type "Literal['test']", variable has type "Callable[[], Tuple[Literal['test']]]")
2451-
pass
2451+
reveal_type(x) # N: Revealed type is "def () -> Tuple[Literal['test']]"
24522452
case foo:
24532453
foo
24542454

@@ -2460,11 +2460,33 @@ class Some:
24602460
value: int | str
24612461
__match_args__ = ("value",)
24622462

2463-
def some(x: Some) -> None:
2463+
def fn1(x: Some | int | str) -> None:
24642464
match x:
24652465
case int():
24662466
def value():
24672467
return 1
2468+
reveal_type(value) # N: Revealed type is "def () -> Any"
2469+
case str():
2470+
def value():
2471+
return 1
2472+
reveal_type(value) # N: Revealed type is "def () -> Any"
24682473
case Some(value): # E: Incompatible types in capture pattern (pattern captures type "Union[int, str]", variable has type "Callable[[], Any]")
24692474
pass
2475+
2476+
def fn2(x: Some | int | str) -> None:
2477+
match x:
2478+
case int():
2479+
def value() -> str:
2480+
return ""
2481+
reveal_type(value) # N: Revealed type is "def () -> builtins.str"
2482+
case str():
2483+
def value() -> int: # E: All conditional function variants must have identical signatures \
2484+
# N: Original: \
2485+
# N: def value() -> str \
2486+
# N: Redefinition: \
2487+
# N: def value() -> int
2488+
return 1
2489+
reveal_type(value) # N: Revealed type is "def () -> builtins.str"
2490+
case Some(value): # E: Incompatible types in capture pattern (pattern captures type "Union[int, str]", variable has type "Callable[[], str]")
2491+
pass
24702492
[builtins fixtures/dict.pyi]

0 commit comments

Comments
 (0)