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 neologix
Recipients gvanrossum, neologix, pitrou
Date 2013-11-30.13:44:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1385819076.05.0.513809645025.issue19842@psf.upfronthosting.co.za>
In-reply-to
Content
Initially, BaseSelector was simply designed as the base implementation used by concrete ones like SelectSelector & Co.

Then BaseSelector evolved to be an ABC, but the problem is that it's really not usable as such: the register() and unregister() methods are not abstract, and instead store the fileobj -> key association in a private dictionary (_fd_to_key). Since this attribute is private, it cannot be used by third-party selectors implementation which might want to implement the ABC. Also, such implementations might not want to use a dictionay internally, and generally, inheritance should be avoided in this type of situations (since it breaks encapsulation).

In short, BaseSelector mixes up the type definition (ABC) and base implementation, which cannot be reused by subclasses anyway.

The attached patch cleans things up by making BaseSelector.{register,unregister,get_map} methods abstract (raising NotImplementedError by default).
Together with select(), those methods are the bare minimum that a conform selector implementation should provide.
get_key() still has a default implementation (atop get_map()), and so does modify() (atop register()/unregister()).

The concrete base implementation (on top of which are built SelectSelector & friends) is moved in a private _BaseSelectorImpl.

I think that's a cleaner design.

The only problem is that it makes some methods abstract, so I had to update test_telnetlib and asyncio/test_utils because they are implementing BaseSelector for mock tests.

BTW, is there a consensus on ABC names? Like AbstractSelector vs BaseSelector?
History
Date User Action Args
2013-11-30 13:44:36neologixsetrecipients: + neologix, gvanrossum, pitrou
2013-11-30 13:44:36neologixsetmessageid: <1385819076.05.0.513809645025.issue19842@psf.upfronthosting.co.za>
2013-11-30 13:44:35neologixlinkissue19842 messages
2013-11-30 13:44:35neologixcreate