@@ -1948,12 +1948,7 @@ def analyze_type_type_callee(self, item: ProperType, context: Context) -> Type:
19481948 # but better than AnyType...), but replace the return type
19491949 # with typevar.
19501950 callee = self .analyze_type_type_callee (get_proper_type (item .upper_bound ), context )
1951- callee = get_proper_type (callee )
1952- if isinstance (callee , CallableType ):
1953- callee = callee .copy_modified (ret_type = item )
1954- elif isinstance (callee , Overloaded ):
1955- callee = Overloaded ([c .copy_modified (ret_type = item ) for c in callee .items ])
1956- return callee
1951+ return self .replace_type_type_callee_ret_type (callee , item )
19571952 # We support Type of namedtuples but not of tuples in general
19581953 if isinstance (item , TupleType ) and tuple_fallback (item ).type .fullname != "builtins.tuple" :
19591954 return self .analyze_type_type_callee (tuple_fallback (item ), context )
@@ -1963,6 +1958,23 @@ def analyze_type_type_callee(self, item: ProperType, context: Context) -> Type:
19631958 self .msg .unsupported_type_type (item , context )
19641959 return AnyType (TypeOfAny .from_error )
19651960
1961+ def replace_type_type_callee_ret_type (self , callee : Type , ret_type : Type ) -> Type :
1962+ callee = get_proper_type (callee )
1963+ if isinstance (callee , CallableType ):
1964+ return callee .copy_modified (ret_type = ret_type )
1965+ if isinstance (callee , Overloaded ):
1966+ return Overloaded ([c .copy_modified (ret_type = ret_type ) for c in callee .items ])
1967+ if isinstance (callee , UnionType ):
1968+ return UnionType (
1969+ [
1970+ self .replace_type_type_callee_ret_type (item , ret_type )
1971+ for item in callee .relevant_items ()
1972+ ],
1973+ line = callee .line ,
1974+ column = callee .column ,
1975+ )
1976+ return callee
1977+
19661978 def infer_arg_types_in_empty_context (self , args : list [Expression ]) -> list [Type ]:
19671979 """Infer argument expression types in an empty context.
19681980
0 commit comments