Skip to content

Commit e277471

Browse files
committed
Use typing.get_overloads.
1 parent e2b6548 commit e277471

2 files changed

Lines changed: 6 additions & 18 deletions

File tree

typemap/type_eval/_apply_generic.py

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ def get_local_defns(
296296
) -> tuple[
297297
dict[str, Any],
298298
dict[
299-
str, types.FunctionType | classmethod | staticmethod | WrappedOverloaded
299+
str, types.FunctionType | classmethod | staticmethod | WrappedOverloads
300300
],
301301
]:
302302
from typemap.typing import GenericCallable
@@ -334,8 +334,8 @@ def get_local_defns(
334334
# XXX: This is totally wrong; we still need to do
335335
# substitute in class vars
336336
local_fn = stuff
337-
elif overloaded := _is_overloaded_function(stuff):
338-
local_fn = overloaded
337+
elif overloads := typing.get_overloads(stuff):
338+
local_fn = WrappedOverloads(tuple(overloads))
339339

340340
# If we got stuck, we build a GenericCallable that
341341
# computes the type once it has been given type
@@ -380,20 +380,8 @@ def lam(*vs):
380380

381381

382382
@dataclasses.dataclass(frozen=True)
383-
class WrappedOverloaded:
384-
functions: tuple[types.FunctionType, ...]
385-
386-
387-
def _is_overloaded_function(func):
388-
module_overload_registry = typing._overload_registry[func.__module__]
389-
if not module_overload_registry:
390-
return None
391-
392-
func_overload_registry = module_overload_registry[func.__qualname__]
393-
if not func_overload_registry:
394-
return
395-
396-
return WrappedOverloaded(tuple(func_overload_registry.values()))
383+
class WrappedOverloads:
384+
functions: tuple[typing.Callable[..., Any], ...]
397385

398386

399387
def flatten_class_new_proto(cls: type) -> type:

typemap/type_eval/_eval_operators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def get_annotated_method_hints(cls, *, ctx):
170170
object,
171171
acls,
172172
)
173-
elif isinstance(attr, _apply_generic.WrappedOverloaded):
173+
elif isinstance(attr, _apply_generic.WrappedOverloads):
174174
overloads = [
175175
_function_type(_eval_types(of, ctx), receiver_type=acls)
176176
for of in attr.functions

0 commit comments

Comments
 (0)