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

Spencer Brown report at bugs.python.org
Tue Feb 22 01:51:20 EST 2022


Spencer Brown <spencerb21 at live.com> added the comment:

Had a potential thought. Since the only situation we care about is overload being used on function definitions in lexical order, valid calls are only that on definitions with ascending co_firstlineno counts. Expanding on Jelle's solution, the overload() decorator could compare the current function's line number to the first in the list, and if it's <= clear out the list (we're re-defining). Then repeated re-definitions wouldn't duplicate overloads. 

The other change I'd suggest is to make get_overloads_for() first check __overloads__, then only if not present pop from the _overloads dict and assign to that attribute. That way if code calls get_overloads_for() at least once, the function will be referring to the actual overloads created at the same time. It'd also get garbage collected then when the function dies. It also means you could manually assign to add overloads to any callable.

----------

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


More information about the Python-bugs-list mailing list