Skip to content

Commit 0bcf1dd

Browse files
allow get_isinstance_type to return empty list
1 parent 72c0486 commit 0bcf1dd

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

mypy/checker.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7755,11 +7755,8 @@ def get_isinstance_type(self, expr: Expression) -> list[TypeRange] | None:
77557755
types.append(TypeRange(typ, is_upper_bound=False))
77567756
else: # we didn't see an actual type, but rather a variable with unknown value
77577757
return None
7758-
if not types:
7759-
# this can happen if someone has empty tuple as 2nd argument to isinstance
7760-
# strictly speaking, we should return UninhabitedType but for simplicity we will simply
7761-
# refuse to do any type inference for now
7762-
return None
7758+
# Note: types can be an empty list, for example in `isinstance(x, ())`,
7759+
# which always returns False at runtime.
77637760
return types
77647761

77657762
def is_literal_enum(self, n: Expression) -> bool:
@@ -8003,6 +8000,8 @@ def conditional_types(
80038000
None means no new information can be inferred.
80048001
If default is set it is returned instead.
80058002
"""
8003+
if proposed_type_ranges is None:
8004+
return current_type, default
80068005
if not proposed_type_ranges:
80078006
return UninhabitedType(), default
80088007

0 commit comments

Comments
 (0)