210210# Type of callback user for checking individual function arguments. See
211211# check_args() below for details.
212212ArgChecker : _TypeAlias = Callable [
213- [Type , Type , ArgKind , Type , int , int , CallableType , Optional [Type ], Context , Context ], None
213+ [Type , Type , ArgKind , Type , int , int , CallableType , Optional [Type ], Context , Context , bool ],
214+ None ,
214215]
215216
216217# Maximum nesting level for math union in overloads, setting this to large values
@@ -2175,6 +2176,13 @@ def infer_function_type_arguments(
21752176 Return a derived callable type that has the arguments applied.
21762177 """
21772178 if self .chk .in_checked_function ():
2179+ if isinstance (callee_type .ret_type , TypeVarType ):
2180+ # if the return type is constant, infer as literal
2181+ rvalue_type = [
2182+ remove_instance_last_known_values (arg ) if isinstance (arg , Instance ) else arg
2183+ for arg in args
2184+ ]
2185+
21782186 # Disable type errors during type inference. There may be errors
21792187 # due to partial available context information at this time, but
21802188 # these errors can be safely ignored as the arguments will be
@@ -2581,6 +2589,8 @@ def check_argument_types(
25812589 context : Context ,
25822590 check_arg : ArgChecker | None = None ,
25832591 object_type : Type | None = None ,
2592+ * ,
2593+ type_function = False ,
25842594 ) -> None :
25852595 """Check argument types against a callable type.
25862596
@@ -2712,6 +2722,7 @@ def check_argument_types(
27122722 object_type ,
27132723 args [actual ],
27142724 context ,
2725+ type_function ,
27152726 )
27162727
27172728 def check_arg (
@@ -2726,12 +2737,16 @@ def check_arg(
27262737 object_type : Type | None ,
27272738 context : Context ,
27282739 outer_context : Context ,
2740+ type_function = False ,
27292741 ) -> None :
27302742 """Check the type of a single argument in a call."""
27312743 caller_type = get_proper_type (caller_type )
27322744 original_caller_type = get_proper_type (original_caller_type )
27332745 callee_type = get_proper_type (callee_type )
2734-
2746+ if type_function :
2747+ # TODO: make this work at all
2748+ if not isinstance (caller_type , Instance ) or not caller_type .last_known_value :
2749+ caller_type = self .named_type ("builtins.object" )
27352750 if isinstance (caller_type , DeletedType ):
27362751 self .msg .deleted_as_rvalue (caller_type , context )
27372752 # Only non-abstract non-protocol class can be given where Type[...] is expected...
@@ -3348,6 +3363,7 @@ def check_arg(
33483363 object_type : Type | None ,
33493364 context : Context ,
33503365 outer_context : Context ,
3366+ type_function : bool ,
33513367 ) -> None :
33523368 if not arg_approximate_similarity (caller_type , callee_type ):
33533369 # No match -- exit early since none of the remaining work can change
@@ -3580,10 +3596,14 @@ def visit_bytes_expr(self, e: BytesExpr) -> Type:
35803596
35813597 def visit_float_expr (self , e : FloatExpr ) -> Type :
35823598 """Type check a float literal (trivial)."""
3599+ if mypy .options ._based :
3600+ return self .infer_literal_expr_type (e .value , "builtins.float" )
35833601 return self .named_type ("builtins.float" )
35843602
35853603 def visit_complex_expr (self , e : ComplexExpr ) -> Type :
35863604 """Type check a complex literal."""
3605+ if mypy .options ._based :
3606+ return self .infer_literal_expr_type (e .value , "builtins.complex" )
35873607 return self .named_type ("builtins.complex" )
35883608
35893609 def visit_ellipsis (self , e : EllipsisExpr ) -> Type :
0 commit comments