@@ -353,10 +353,11 @@ class FineGrainedDeferredNode(NamedTuple):
353353# Keeps track of partial types in a single scope. In fine-grained incremental
354354# mode partial types initially defined at the top level cannot be completed in
355355# a function, and we use the 'is_function' attribute to enforce this.
356- class PartialTypeScope (NamedTuple ):
357- map : dict [Var , Context ]
358- is_function : bool
359- is_local : bool
356+ class PartialTypeScope :
357+ def __init__ (self , map : dict [Var , Context ], is_function : bool , is_local : bool ) -> None :
358+ self .map : Final = map
359+ self .is_function : Final = is_function
360+ self .is_local : Final = is_local
360361
361362
362363class LocalTypeMap :
@@ -1617,14 +1618,14 @@ def check_func_def(
16171618 else :
16181619 msg = message_registry .MISSING_RETURN_STATEMENT
16191620 if body_is_trivial :
1620- msg = msg ._replace ( code = codes .EMPTY_BODY )
1621+ msg = ErrorMessage ( msg .value , code = codes .EMPTY_BODY )
16211622 self .fail (msg , defn )
16221623 if may_be_abstract :
16231624 self .note (message_registry .EMPTY_BODY_ABSTRACT , defn )
16241625 else :
16251626 msg = message_registry .INCOMPATIBLE_RETURN_VALUE_TYPE
16261627 if body_is_trivial :
1627- msg = msg ._replace ( code = codes .EMPTY_BODY )
1628+ msg = ErrorMessage ( msg .value , code = codes .EMPTY_BODY )
16281629 # similar to code in check_return_stmt
16291630 if (
16301631 not self .check_subtype (
@@ -7208,14 +7209,23 @@ def replay_lookup(new_parent_type: ProperType) -> Type | None:
72087209 if int_literals is not None :
72097210
72107211 def replay_lookup (new_parent_type : ProperType ) -> Type | None :
7211- if not isinstance (new_parent_type , TupleType ):
7212- return None
7213- try :
7214- assert int_literals is not None
7215- member_types = [new_parent_type .items [key ] for key in int_literals ]
7216- except IndexError :
7217- return None
7218- return make_simplified_union (member_types )
7212+ if isinstance (new_parent_type , TupleType ):
7213+ try :
7214+ assert int_literals is not None
7215+ member_types = [
7216+ new_parent_type .items [key ] for key in int_literals
7217+ ]
7218+ except IndexError :
7219+ return None
7220+ return make_simplified_union (member_types )
7221+ if (
7222+ isinstance (new_parent_type , Instance )
7223+ and new_parent_type .type .fullname
7224+ in ("builtins.list" , "builtins.tuple" )
7225+ and new_parent_type .args
7226+ ):
7227+ return new_parent_type .args [0 ]
7228+ return None
72197229
72207230 else :
72217231 return output
@@ -7874,7 +7884,7 @@ def enter_partial_types(
78747884 self .options .check_untyped_defs and self .dynamic_funcs and self .dynamic_funcs [- 1 ]
78757885 )
78767886
7877- partial_types , _ , _ = self .partial_types .pop ()
7887+ partial_types = self .partial_types .pop (). map
78787888 if not self .current_node_deferred :
78797889 for var , context in partial_types .items ():
78807890 if isinstance (var .type , PartialType ) and var .type .type is None and not permissive :
@@ -8914,24 +8924,9 @@ def reduce_and_conditional_type_maps(ms: list[TypeMap], *, use_meet: bool) -> Ty
89148924 return result
89158925
89168926
8917- BUILTINS_CUSTOM_EQ_CHECKS : Final = {
8918- "builtins.frozenset" ,
8919- "_collections_abc.dict_keys" ,
8920- "_collections_abc.dict_items" ,
8921- }
8922-
8923-
89248927def has_custom_eq_checks (t : Type ) -> bool :
8925- return (
8926- custom_special_method (t , "__eq__" , check_all = False )
8927- or custom_special_method (t , "__ne__" , check_all = False )
8928- # custom_special_method has special casing for builtins.* and typing.* that make the
8929- # above always return False. Some builtin collections still have equality behavior that
8930- # crosses nominal type boundaries and isn't captured by VALUE_EQUALITY_TYPE_DOMAINS.
8931- or (
8932- isinstance (pt := get_proper_type (t ), Instance )
8933- and pt .type .fullname in BUILTINS_CUSTOM_EQ_CHECKS
8934- )
8928+ return custom_special_method (t , "__eq__" , check_all = False ) or custom_special_method (
8929+ t , "__ne__" , check_all = False
89358930 )
89368931
89378932
@@ -9721,6 +9716,8 @@ def visit_starred_pattern(self, p: StarredPattern) -> None:
97219716 "builtins.bytes" : "builtins.bytes" ,
97229717 "builtins.bytearray" : "builtins.bytes" ,
97239718 "builtins.memoryview" : "builtins.bytes" ,
9719+ "typing.Mapping" : "typing.Mapping" ,
9720+ "typing.AbstractSet" : "typing.AbstractSet" ,
97249721}
97259722
97269723VALUE_EQUALITY_DOMAINS : Final = {** OPEN_VALUE_EQUALITY_DOMAINS , ** CLOSED_VALUE_EQUALITY_DOMAINS }
0 commit comments