Skip to content

Commit 8451b92

Browse files
committed
Fix reachability for frozenset and dict view narrowing
Fixes #21143 (on the same lines as #20704) 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 ef7e8a6 commit 8451b92

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
@@ -8731,7 +8731,13 @@ def reduce_and_conditional_type_maps(ms: list[TypeMap], *, use_meet: bool) -> Ty
87318731
return result
87328732

87338733

8734-
BUILTINS_CUSTOM_EQ_CHECKS: Final = {"builtins.bytearray", "builtins.memoryview"}
8734+
BUILTINS_CUSTOM_EQ_CHECKS: Final = {
8735+
"builtins.bytearray",
8736+
"builtins.memoryview",
8737+
"builtins.frozenset",
8738+
"_collections_abc.dict_keys",
8739+
"_collections_abc.dict_items",
8740+
}
87358741

87368742

87378743
def has_custom_eq_checks(t: Type) -> bool:
@@ -8741,7 +8747,7 @@ def has_custom_eq_checks(t: Type) -> bool:
87418747
# custom_special_method has special casing for builtins.* and typing.* that make the
87428748
# above always return False. So here we return True if the a value of a builtin type
87438749
# will ever compare equal to value of another type, e.g. a bytes value can compare equal
8744-
# to a bytearray value. We also include builtins collections, see testNarrowingCollections
8750+
# to a bytearray value.
87458751
or (
87468752
isinstance(pt := get_proper_type(t), Instance)
87478753
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)