Skip to content

Commit a8ce02d

Browse files
committed
Pass _function_type_from_sig the type instead of the whole function.
1 parent 6fec515 commit a8ce02d

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

typemap/type_eval/_apply_generic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ def lam(*vs):
375375
)
376376
sig = _resolved_function_signature(fn, args)
377377
return _function_type_from_sig(
378-
sig, o, receiver_type=cls
378+
sig, type(o), receiver_type=cls
379379
)
380380

381381
return lam

typemap/type_eval/_eval_operators.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ def _callable_type_to_method(name, typ, ctx):
679679
return head(func)
680680

681681

682-
def _function_type_from_sig(sig, func, *, receiver_type):
682+
def _function_type_from_sig(sig, func_type, *, receiver_type):
683683
empty = inspect.Parameter.empty
684684

685685
def _ann(x):
@@ -691,12 +691,12 @@ def _ann(x):
691691
for i, p in enumerate(sig.parameters.values()):
692692
ann = p.annotation
693693
# Special handling for first argument on methods.
694-
if i == 0 and receiver_type and not isinstance(func, staticmethod):
694+
if i == 0 and receiver_type and func_type is not staticmethod:
695695
if ann is empty:
696696
ann = receiver_type
697697
else:
698698
if (
699-
isinstance(func, classmethod)
699+
func_type is classmethod
700700
and typing.get_origin(ann) is type
701701
and (receiver_args := typing.get_args(ann))
702702
):
@@ -729,9 +729,9 @@ def _ann(x):
729729
# TODO: Is doing the tuple for staticmethod/classmethod legit?
730730
# Putting a list in makes it unhashable...
731731
f: typing.Any # type: ignore[annotation-unchecked]
732-
if isinstance(func, staticmethod):
732+
if func_type is staticmethod:
733733
f = staticmethod[tuple[*params], ret]
734-
elif isinstance(func, classmethod):
734+
elif func_type is classmethod:
735735
f = classmethod[specified_receiver, tuple[*params[1:]], ret]
736736
else:
737737
f = typing.Callable[params, ret]
@@ -744,7 +744,7 @@ def _function_type(
744744
) -> type[typing.Callable | classmethod | staticmethod | GenericCallable]:
745745
root = inspect.unwrap(func)
746746
sig = inspect.signature(root)
747-
f = _function_type_from_sig(sig, func, receiver_type=receiver_type)
747+
f = _function_type_from_sig(sig, type(func), receiver_type=receiver_type)
748748

749749
if root.__type_params__:
750750
# Must store a lambda that performs type variable substitution

0 commit comments

Comments
 (0)