@@ -281,7 +281,14 @@ def _resolved_function_signature(func, args):
281281 return sig
282282
283283
284- def get_local_defns (boxed : Boxed ) -> tuple [dict [str , Any ], dict [str , Any ]]:
284+ def get_local_defns (
285+ boxed : Boxed ,
286+ ) -> tuple [
287+ dict [str , Any ],
288+ dict [
289+ str , types .FunctionType | classmethod | staticmethod | WrappedOverloaded
290+ ],
291+ ]:
285292 from typemap .typing import GenericCallable
286293
287294 annos : dict [str , Any ] = {}
@@ -315,6 +322,8 @@ def get_local_defns(boxed: Boxed) -> tuple[dict[str, Any], dict[str, Any]]:
315322 # XXX: This is totally wrong; we still need to do
316323 # substitute in class vars
317324 local_fn = stuff
325+ elif overloaded := _is_overloaded_function (stuff ):
326+ local_fn = overloaded
318327
319328 # If we got stuck, we build a GenericCallable that
320329 # computes the type once it has been given type
@@ -358,6 +367,23 @@ def lam(*vs):
358367 return annos , dct
359368
360369
370+ @dataclasses .dataclass (frozen = True )
371+ class WrappedOverloaded :
372+ functions : tuple [types .FunctionType , ...]
373+
374+
375+ def _is_overloaded_function (func ):
376+ module_overload_registry = typing ._overload_registry [func .__module__ ]
377+ if not module_overload_registry :
378+ return None
379+
380+ func_overload_registry = module_overload_registry [func .__qualname__ ]
381+ if not func_overload_registry :
382+ return
383+
384+ return WrappedOverloaded (tuple (func_overload_registry .values ()))
385+
386+
361387def flatten_class_new_proto (cls : type ) -> type :
362388 # This is a hacky version of flatten_class that works by using
363389 # NewProtocol on Members!
0 commit comments