Skip to content

Commit 6fccffc

Browse files
committed
Fix reachability for frozenset and dict view narrowing (#21151)
Fixes #21143 (on the same lines as #20704, i.e. there still exists a deeper fix that could be made) I also update a comment that is a little out of date since #20863 and code in checkexpr.py that is out of date for modern typeshed
1 parent de50419 commit 6fccffc

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

mypy/checker.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8734,7 +8734,13 @@ def reduce_and_conditional_type_maps(ms: list[TypeMap], *, use_meet: bool) -> Ty
87348734
return result
87358735

87368736

8737-
BUILTINS_CUSTOM_EQ_CHECKS: Final = {"builtins.bytearray", "builtins.memoryview"}
8737+
BUILTINS_CUSTOM_EQ_CHECKS: Final = {
8738+
"builtins.bytearray",
8739+
"builtins.memoryview",
8740+
"builtins.frozenset",
8741+
"_collections_abc.dict_keys",
8742+
"_collections_abc.dict_items",
8743+
}
87388744

87398745

87408746
def has_custom_eq_checks(t: Type) -> bool:
@@ -8744,7 +8750,7 @@ def has_custom_eq_checks(t: Type) -> bool:
87448750
# custom_special_method has special casing for builtins.* and typing.* that make the
87458751
# above always return False. So here we return True if the a value of a builtin type
87468752
# will ever compare equal to value of another type, e.g. a bytes value can compare equal
8747-
# to a bytearray value. We also include builtins collections, see testNarrowingCollections
8753+
# to a bytearray value.
87488754
or (
87498755
isinstance(pt := get_proper_type(t), Instance)
87508756
and pt.type.fullname in BUILTINS_CUSTOM_EQ_CHECKS

mypy/checkexpr.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,6 @@
236236
"builtins.frozenset",
237237
"typing.KeysView",
238238
"typing.ItemsView",
239-
"builtins._dict_keys",
240-
"builtins._dict_items",
241239
"_collections_abc.dict_keys",
242240
"_collections_abc.dict_items",
243241
]

0 commit comments

Comments
 (0)