241241from mypy .typevars import fill_typevars , fill_typevars_with_any , has_no_typevars
242242from mypy .util import is_dunder , is_sunder
243243from mypy .visitor import NodeVisitor
244- from mypy .types import LiteralType
245244
246245T = TypeVar ("T" )
247246
@@ -6581,18 +6580,18 @@ def comparison_type_narrowing_helper(self, node: ComparisonExpr) -> tuple[TypeMa
65816580
65826581 if left_index in narrowable_operand_index_to_hash :
65836582 # We only try and narrow away 'None' for now
6584- if is_overlapping_none (item_type ):
6585- collection_item_type = get_proper_type (builtin_item_type (iterable_type ))
6586- if (
6587- collection_item_type is not None
6588- and not is_overlapping_none (collection_item_type )
6589- and not (
6590- isinstance (collection_item_type , Instance )
6591- and collection_item_type .type .fullname == "builtins.object"
6592- )
6593- and is_overlapping_erased_types (item_type , collection_item_type )
6594- ):
6595- if_map [operands [left_index ]] = remove_optional (item_type )
6583+ if is_overlapping_none (item_type ):
6584+ collection_item_type = get_proper_type (builtin_item_type (iterable_type ))
6585+ if (
6586+ collection_item_type is not None
6587+ and not is_overlapping_none (collection_item_type )
6588+ and not (
6589+ isinstance (collection_item_type , Instance )
6590+ and collection_item_type .type .fullname == "builtins.object"
6591+ )
6592+ and is_overlapping_erased_types (item_type , collection_item_type )
6593+ ):
6594+ if_map [operands [left_index ]] = remove_optional (item_type )
65966595 if_map [operands [left_index ]] = remove_optional (item_type )
65976596 literal_types = []
65986597 if isinstance (get_proper_type (iterable_type ), TupleType ):
@@ -6603,7 +6602,10 @@ def comparison_type_narrowing_helper(self, node: ComparisonExpr) -> tuple[TypeMa
66036602
66046603 if item_type .type .is_enum :
66056604 # Enum values in tuples are represented as Instance types, not LiteralType
6606- if hasattr (item_type , 'last_known_value' ) and item_type .last_known_value :
6605+ if (
6606+ hasattr (item_type , "last_known_value" )
6607+ and item_type .last_known_value
6608+ ):
66076609 # Use the existing literal representation
66086610 literal_types .append (item_type .last_known_value )
66096611 else :
0 commit comments