Message414561
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. |
|
Date |
User |
Action |
Args |
2022-03-05 03:45:06 | JelleZijlstra | set | recipients:
+ JelleZijlstra, rhettinger, ronaldoussoren, Spencer Brown, sobolevn, kj, AlexWaygood, DiddiLeija |
2022-03-05 03:45:06 | JelleZijlstra | set | messageid: <1646451906.03.0.606332774317.issue45100@roundup.psfhosted.org> |
2022-03-05 03:45:06 | JelleZijlstra | link | issue45100 messages |
2022-03-05 03:45:05 | JelleZijlstra | create | |
|