This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author JelleZijlstra
Recipients AlexWaygood, DiddiLeija, JelleZijlstra, Spencer Brown, kj, rhettinger, ronaldoussoren, sobolevn
Date 2022-03-05.03:45:05
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1646451906.03.0.606332774317.issue45100@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2022-03-05 03:45:06JelleZijlstrasetrecipients: + JelleZijlstra, rhettinger, ronaldoussoren, Spencer Brown, sobolevn, kj, AlexWaygood, DiddiLeija
2022-03-05 03:45:06JelleZijlstrasetmessageid: <1646451906.03.0.606332774317.issue45100@roundup.psfhosted.org>
2022-03-05 03:45:06JelleZijlstralinkissue45100 messages
2022-03-05 03:45:05JelleZijlstracreate