@@ -1420,7 +1420,11 @@ def is_generic_decorator_overload_call(
14201420 return None
14211421
14221422 def handle_decorator_overload_call (
1423- self , callee_type : CallableType , overloaded : Overloaded , ctx : Context
1423+ self ,
1424+ callee_type : CallableType ,
1425+ overloaded : Overloaded ,
1426+ ctx : Context ,
1427+ callee_is_overload_item : bool ,
14241428 ) -> tuple [Type , Type ] | None :
14251429 """Type-check application of a generic callable to an overload.
14261430
@@ -1432,7 +1436,9 @@ def handle_decorator_overload_call(
14321436 for item in overloaded .items :
14331437 arg = TempNode (typ = item )
14341438 with self .msg .filter_errors () as err :
1435- item_result , inferred_arg = self .check_call (callee_type , [arg ], [ARG_POS ], ctx )
1439+ item_result , inferred_arg = self .check_call (
1440+ callee_type , [arg ], [ARG_POS ], ctx , is_overload_item = callee_is_overload_item
1441+ )
14361442 if err .has_new_errors ():
14371443 # This overload doesn't match.
14381444 continue
@@ -1538,6 +1544,7 @@ def check_call(
15381544 callable_name : str | None = None ,
15391545 object_type : Type | None = None ,
15401546 original_type : Type | None = None ,
1547+ is_overload_item : bool = False ,
15411548 ) -> tuple [Type , Type ]:
15421549 """Type check a call.
15431550
@@ -1558,6 +1565,7 @@ def check_call(
15581565 or None if unavailable (examples: 'builtins.open', 'typing.Mapping.get')
15591566 object_type: If callable_name refers to a method, the type of the object
15601567 on which the method is being called
1568+ is_overload_item: Whether this check is for an individual overload item
15611569 """
15621570 callee = get_proper_type (callee )
15631571
@@ -1568,7 +1576,7 @@ def check_call(
15681576 # Special casing for inline application of generic callables to overloads.
15691577 # Supporting general case would be tricky, but this should cover 95% of cases.
15701578 overloaded_result = self .handle_decorator_overload_call (
1571- callee , overloaded , context
1579+ callee , overloaded , context , is_overload_item
15721580 )
15731581 if overloaded_result is not None :
15741582 return overloaded_result
@@ -1582,6 +1590,7 @@ def check_call(
15821590 callable_node ,
15831591 callable_name ,
15841592 object_type ,
1593+ is_overload_item ,
15851594 )
15861595 elif isinstance (callee , Overloaded ):
15871596 return self .check_overload_call (
@@ -1659,33 +1668,26 @@ def check_callable_call(
16591668 callable_node : Expression | None ,
16601669 callable_name : str | None ,
16611670 object_type : Type | None ,
1671+ is_overload_item : bool = False ,
16621672 ) -> tuple [Type , Type ]:
16631673 """Type check a call that targets a callable value.
16641674
16651675 See the docstring of check_call for more information.
16661676 """
1677+ # Check implicit calls to deprecated class constructors.
1678+ # Only the non-overload case is handled here. Overloaded constructors are handled
1679+ # separately during overload resolution.
1680+ if (not is_overload_item ) and callee .is_type_obj ():
1681+ self .chk .warn_deprecated (callee .definition , context )
1682+
16671683 # Always unpack **kwargs before checking a call.
16681684 callee = callee .with_unpacked_kwargs ().with_normalized_var_args ()
16691685 if callable_name is None and callee .name :
16701686 callable_name = callee .name
16711687 ret_type = get_proper_type (callee .ret_type )
16721688 if callee .is_type_obj () and isinstance (ret_type , Instance ):
16731689 callable_name = ret_type .type .fullname
1674- if isinstance (callable_node , RefExpr ):
1675- # Check implicit calls to deprecated class constructors.
1676- # Only the non-overload case is handled here. Overloaded constructors are handled
1677- # separately during overload resolution. `callable_node` is `None` for an overload
1678- # item so deprecation checks are not duplicated.
1679- callable_info : TypeInfo | None = None
1680- if isinstance (callable_node .node , TypeInfo ):
1681- callable_info = callable_node .node
1682- elif isinstance (callable_node .node , TypeAlias ):
1683- alias_target = get_proper_type (callable_node .node .target )
1684- if isinstance (alias_target , Instance ) and isinstance (alias_target .type , TypeInfo ):
1685- callable_info = alias_target .type
1686- if callable_info is not None :
1687- self .chk .check_deprecated (callee .definition , context )
1688-
1690+ if isinstance (callable_node , RefExpr ) and (callable_node .fullname in ENUM_BASES ):
16891691 if callable_node .fullname in ENUM_BASES :
16901692 # An Enum() call that failed SemanticAnalyzerPass2.check_enum_call().
16911693 return callee .ret_type , callee
@@ -2925,6 +2927,7 @@ def infer_overload_return_type(
29252927 context = context ,
29262928 callable_name = callable_name ,
29272929 object_type = object_type ,
2930+ is_overload_item = True ,
29282931 )
29292932 is_match = not w .has_new_errors ()
29302933 if is_match :
0 commit comments