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 Spencer Brown
Recipients AlexWaygood, DiddiLeija, JelleZijlstra, Spencer Brown, gvanrossum, kj, rhettinger, ronaldoussoren
Date 2022-02-22.06:51:20
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645512680.87.0.61171562289.issue45100@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2022-02-22 06:51:20Spencer Brownsetrecipients: + Spencer Brown, gvanrossum, rhettinger, ronaldoussoren, JelleZijlstra, kj, AlexWaygood, DiddiLeija
2022-02-22 06:51:20Spencer Brownsetmessageid: <1645512680.87.0.61171562289.issue45100@roundup.psfhosted.org>
2022-02-22 06:51:20Spencer Brownlinkissue45100 messages
2022-02-22 06:51:20Spencer Browncreate