Skip to content

Commit 2bd7350

Browse files
committed
Reorder the branches for clarity.
1 parent c328baf commit 2bd7350

File tree

1 file changed

+26
-21
lines changed

1 file changed

+26
-21
lines changed

typemap/type_eval/_apply_generic.py

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -357,20 +357,6 @@ def get_local_defns(
357357
stuff = inspect.unwrap(orig)
358358

359359
if isinstance(stuff, types.FunctionType):
360-
# TODO: This annos_ok thing is a hack because processing
361-
# __annotations__ on methods broke stuff and I didn't want
362-
# to chase it down yet.
363-
resolved_sig = None
364-
try:
365-
resolved_sig = _resolved_function_signature(
366-
stuff,
367-
boxed.str_args,
368-
definition_cls=boxed.cls,
369-
)
370-
except _eval_typing.StuckException:
371-
pass
372-
overloads = typing.get_overloads(stuff)
373-
374360
# If the method has type params, we build a GenericCallable
375361
# (in annos only) so that [Z] etc. are preserved in output.
376362
if stuff.__type_params__:
@@ -410,13 +396,9 @@ def lam(*vs):
410396
),
411397
]
412398
dct[name] = gc
413-
elif resolved_sig is not None:
414-
dct[name] = _function_type_from_sig(
415-
resolved_sig,
416-
type(orig),
417-
receiver_type=boxed.alias_type(),
418-
)
419-
elif overloads:
399+
400+
elif overloads := typing.get_overloads(stuff):
401+
# If the method is overloaded, build an Overloaded type.
420402
overload_types: typing.Sequence[
421403
type[
422404
typing.Callable
@@ -433,6 +415,29 @@ def lam(*vs):
433415
]
434416

435417
dct[name] = Overloaded[*overload_types] # type: ignore[valid-type]
418+
continue
419+
420+
else:
421+
# Try to resolve the signature as a normal function.
422+
resolved_sig = None
423+
try:
424+
resolved_sig = _resolved_function_signature(
425+
stuff,
426+
boxed.str_args,
427+
definition_cls=boxed.cls,
428+
)
429+
except _eval_typing.StuckException:
430+
# We can get stuck if the signature has external type vars.
431+
# Just fallback to the original signature for now.
432+
resolved_sig = inspect.signature(stuff)
433+
434+
if resolved_sig is not None:
435+
dct[name] = _function_type_from_sig(
436+
resolved_sig,
437+
type(orig),
438+
receiver_type=boxed.alias_type(),
439+
)
440+
continue
436441

437442
return annos, dct
438443

0 commit comments

Comments
 (0)