New submission from Charles-François Natali:
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?
----------
components: Library (Lib)
files: selectors_base_impl.diff
keywords: needs review, patch
messages: 204809
nosy: gvanrossum, neologix, pitrou
priority: normal
severity: normal
stage: patch review
status: open
title: selectors: refactor BaseSelector implementation
type: behavior
versions: Python 3.4
Added file: http://bugs.python.org/file32906/selectors_base_impl.diff
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue19842>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com