Skip to content

Commit 0c05643

Browse files
committed
Limit legacy guard scope
1 parent a95bb8e commit 0c05643

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

mypy/binder.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
Type,
2222
TypeOfAny,
2323
TypeType,
24+
TypeVarType,
2425
UnionType,
2526
UnpackType,
2627
find_unpack_in_list,
@@ -247,8 +248,10 @@ def update_from_options(self, frames: list[Frame]) -> bool:
247248
type = possible_types[0]
248249
else:
249250
type = make_simplified_union(possible_types)
250-
# Legacy guard for corner case, e.g. when the original type is TypeVarType.
251-
if declaration_type is not None and not is_subtype(type, declaration_type):
251+
# Legacy guard for corner case when the original type is TypeVarType.
252+
if isinstance(declaration_type, TypeVarType) and not is_subtype(
253+
type, declaration_type
254+
):
252255
type = declaration_type
253256
# Try simplifying resulting type for unions involving variadic tuples.
254257
# Technically, everything is still valid without this step, but if we do

test-data/unit/check-narrowing.test

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2431,5 +2431,6 @@ def foo(x: T) -> T:
24312431
pass
24322432
else:
24332433
raise
2434+
reveal_type(x) # N: Revealed type is "T`-1"
24342435
return x
24352436
[builtins fixtures/isinstance.pyi]

0 commit comments

Comments
 (0)