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 josh.r
Recipients josh.r, p-ganssle, serhiy.storchaka, veky
Date 2019-07-26.18:56:56
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1564167416.62.0.659273393209.issue37685@roundup.psfhosted.org>
In-reply-to
Content
Serhiy: Is there a reason not to use the functools.total_ordering decorator on TimerHandle, so you can get rid of __le__/__ge__/__gt__ rather than fixing them individually? I notice at least one behavioral difference (total_ordering's le/ge methods use ==/!= for the fallback comparison, where TimerHandle explicitly calls __eq__) which this would eliminate, along with reducing the code to maintain.

Specifically, the total_ordering fallbacks work if the provided operator (e.g. __lt__) works and either side provides a functional __eq__/__ne__, as appropriate (even if the other side *can't* provide the complementary inequality operator, e.g. __gt__). TimerHandle's behavior differs; it's all or nothing (so if __lt__ works, but __eq__ fails, then the success of __lt__ doesn't matter, the other side has to do everything).

I'm not saying total_ordering is necessarily correct (it does seem a bit odd that A <= B can return True based on a mix of results, one from A.__lt__, one from B.__eq__), but constantly reimplementing these fallback operations has been a source of subtle bugs so often, that I'd rather depend on a single common implementation, and debate tweaks to it there, rather than having it reimplemented slightly differently in a million different places.

I don't think import times for functools should be a problem; looks like at least four asyncio submodules import it, including asyncio.format_helpers (which asyncio.events takes a direct dependency on), so if you're using asyncio.events, you're already importing functools anyway.
History
Date User Action Args
2019-07-26 18:56:56josh.rsetrecipients: + josh.r, serhiy.storchaka, veky, p-ganssle
2019-07-26 18:56:56josh.rsetmessageid: <1564167416.62.0.659273393209.issue37685@roundup.psfhosted.org>
2019-07-26 18:56:56josh.rlinkissue37685 messages
2019-07-26 18:56:56josh.rcreate