[issue45100] Improve help() by making typing.overload() information accessible at runtime

Alex Waygood report at bugs.python.org
Tue Feb 22 17:13:23 EST 2022


Alex Waygood <Alex.Waygood at Gmail.com> added the comment:

I'd dearly like better introspection tools for functions decorated with @overload, but I'd rather have a solution where:

- inspect.signature doesn't have to import typing. That doesn't feel worth it for users who aren't using typing.overload, but inspect.signature would have to import typing whether or not @overload was being used, in order to *check* whether @overload was being used.
- The solution could be reused by, and generalised to, other kinds of functions that have multiple signatures.

If we create an __overloads__ dunder that stored the signatures of multi-signature functions, as Raymond suggests, inspect.signature could check that dunder to examine whether the function is a multi-dispatch signature, and change its representation of the function accordingly. This kind of solution could be easily reused by other parts of the stdlib, like @functools.singledispatch, and by third-party packages such as plum-dispatch, multipledispatch, and Nikita's dry-python/classes library.

So, while it would undoubtedly be more complex to implement, I much prefer Raymond's suggested solution.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue45100>
_______________________________________


More information about the Python-bugs-list mailing list