Jelle Zijlstra <[email protected]> added the comment:
We could make my proposed overload registry more reusable by putting it in a
different module, probably functools. (Another candidate is inspect, but
inspect.py imports functools.py, so that would make it difficult to use the
registry for functools.singledispatch.)
We could then bill it as a "variant registry", with an API like this:
def register_variant(key: str, variant: Callable) -> None: ...
def get_variants(key: str) -> list[Callable]: ...
def get_key_for_callable(callable: Callable) -> str | None: ...
@overload could then call register_variant() to register each overload, and
code that wants a list of overloads (pydoc, inspect.signature, runtime type
checkers) could call get_variants().
get_key_for_callable() essentially does
f"{callable.__qualname__}.{callable.__name__}", but returns None for objects it
can't handle. It will also support at least classmethods and staticmethods.
I will prepare a PR implementing this idea.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue45100>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com