|
45 | 45 | from mypy.expandtype import expand_type |
46 | 46 | from mypy.literals import Key, extract_var_from_literal_hash, literal, literal_hash |
47 | 47 | from mypy.maptype import map_instance_to_supertype |
48 | | -from mypy.meet import is_overlapping_erased_types, is_overlapping_types, meet_types |
| 48 | +from mypy.meet import is_overlapping_types, meet_types |
49 | 49 | from mypy.message_registry import ErrorMessage |
50 | 50 | from mypy.messages import ( |
51 | 51 | SUGGESTED_TEST_FIXTURES, |
|
235 | 235 | is_literal_type, |
236 | 236 | is_named_instance, |
237 | 237 | ) |
238 | | -from mypy.types_utils import is_overlapping_none, remove_optional, store_argument_type, strip_type |
| 238 | +from mypy.types_utils import store_argument_type, strip_type |
239 | 239 | from mypy.typetraverser import TypeTraverserVisitor |
240 | 240 | from mypy.typevars import fill_typevars, fill_typevars_with_any, has_no_typevars |
241 | 241 | from mypy.util import is_dunder, is_sunder |
@@ -6540,19 +6540,6 @@ def comparison_type_narrowing_helper(self, node: ComparisonExpr) -> tuple[TypeMa |
6540 | 6540 | narrowable_indices={0}, |
6541 | 6541 | ) |
6542 | 6542 |
|
6543 | | - # We only try and narrow away 'None' for now |
6544 | | - if ( |
6545 | | - not is_unreachable_map(if_map) |
6546 | | - and is_overlapping_none(item_type) |
6547 | | - and not is_overlapping_none(collection_item_type) |
6548 | | - and not ( |
6549 | | - isinstance(collection_item_type, Instance) |
6550 | | - and collection_item_type.type.fullname == "builtins.object" |
6551 | | - ) |
6552 | | - and is_overlapping_erased_types(item_type, collection_item_type) |
6553 | | - ): |
6554 | | - if_map[operands[left_index]] = remove_optional(item_type) |
6555 | | - |
6556 | 6543 | if right_index in narrowable_operand_index_to_hash: |
6557 | 6544 | if_type, else_type = self.conditional_types_for_iterable( |
6558 | 6545 | item_type, iterable_type |
@@ -6676,6 +6663,8 @@ def narrow_type_by_identity_equality( |
6676 | 6663 | target_type = operand_types[j] |
6677 | 6664 | if should_coerce_literals: |
6678 | 6665 | target_type = coerce_to_literal(target_type) |
| 6666 | + if isinstance(get_proper_type(target_type), Instance): |
| 6667 | + target_type = erase_type(target_type) |
6679 | 6668 |
|
6680 | 6669 | if ( |
6681 | 6670 | # See comments in ambiguous_enum_equality_keys |
@@ -8602,13 +8591,7 @@ def reduce_and_conditional_type_maps(ms: list[TypeMap], *, use_meet: bool) -> Ty |
8602 | 8591 | return result |
8603 | 8592 |
|
8604 | 8593 |
|
8605 | | -BUILTINS_CUSTOM_EQ_CHECKS: Final = { |
8606 | | - "builtins.bytearray", |
8607 | | - "builtins.memoryview", |
8608 | | - "builtins.list", |
8609 | | - "builtins.dict", |
8610 | | - "builtins.set", |
8611 | | -} |
| 8594 | +BUILTINS_CUSTOM_EQ_CHECKS: Final = {"builtins.bytearray", "builtins.memoryview"} |
8612 | 8595 |
|
8613 | 8596 |
|
8614 | 8597 | def has_custom_eq_checks(t: Type) -> bool: |
|
0 commit comments