[issue19172] selectors: add keys() method

2013-10-31 Thread Charles-François Natali
Charles-François Natali added the comment: > Berker Peksag added the comment: > > + .. method:: get_map() > + > + Return a mapping of file objects to selector keys. > > I kind of feel like a walking linter though I think this needs a versionadded > tag :) Well, selectors have been added

[issue19172] selectors: add keys() method

2013-10-31 Thread Berker Peksag
Berker Peksag added the comment: + .. method:: get_map() + + Return a mapping of file objects to selector keys. I kind of feel like a walking linter though I think this needs a versionadded tag :) -- keywords: -needs review nosy: +berker.peksag

[issue19172] selectors: add keys() method

2013-10-30 Thread Charles-François Natali
Charles-François Natali added the comment: Committed. Antoine, thanks for the idea and patch! -- resolution: -> fixed stage: patch review -> committed/rejected status: open -> closed ___ Python tracker __

[issue19172] selectors: add keys() method

2013-10-30 Thread Roundup Robot
Roundup Robot added the comment: New changeset b0ae96700301 by Charles-François Natali in branch 'default': Issue #19172: Add a get_map() method to selectors. http://hg.python.org/cpython/rev/b0ae96700301 -- nosy: +python-dev ___ Python tracker

[issue19172] selectors: add keys() method

2013-10-30 Thread Guido van Rossum
Guido van Rossum added the comment: (Adding CF's new patch so I can compare and review it.) -- Added file: http://bugs.python.org/file32428/selectors_map-2.patch ___ Python tracker _

[issue19172] selectors: add keys() method

2013-10-30 Thread Guido van Rossum
Guido van Rossum added the comment: LGTM. Commit! -- ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://ma

[issue19172] selectors: add keys() method

2013-10-29 Thread Guido van Rossum
Guido van Rossum added the comment: I added some comments to the code review. Please take a look. -- ___ Python tracker ___ ___ Python

[issue19172] selectors: add keys() method

2013-10-25 Thread Charles-François Natali
Charles-François Natali added the comment: > Antoine Pitrou added the comment: > > FWIW, I think the "ideal" solution would be for keys() (*) to return a > read-only Mapping implementation, allowing for file object lookup (using > __getitem__) as well as iteration on SelectorKeys (using __iter__)

[issue19172] selectors: add keys() method

2013-10-06 Thread Antoine Pitrou
Antoine Pitrou added the comment: Here is a proof-of-concept patch adding a get_map() method to Selector (and removing get_key()). -- Added file: http://bugs.python.org/file31977/selectors_map.patch ___ Python tracker

[issue19172] selectors: add keys() method

2013-10-06 Thread Antoine Pitrou
Antoine Pitrou added the comment: > FWIW, I think the "ideal" solution would be for keys() (*) to return a > read-only Mapping implementation, allowing for file object lookup (using > __getitem__) as well as iteration on SelectorKeys (using __iter__) and > fast emptiness checking (using __len__).

[issue19172] selectors: add keys() method

2013-10-06 Thread Antoine Pitrou
Antoine Pitrou added the comment: FWIW, I think the "ideal" solution would be for keys() (*) to return a read-only Mapping implementation, allowing for file object lookup (using __getitem__) as well as iteration on SelectorKeys (using __iter__) and fast emptiness checking (using __len__). (to im

[issue19172] selectors: add keys() method

2013-10-06 Thread STINNER Victor
STINNER Victor added the comment: > Perhaps the method shouldn't be called keys() to avoid any confusion with > subclasses of the Container ABC? If you don't want to rename the SelectorKey class, rename the method to get_keys(). -- ___ Python tracke

[issue19172] selectors: add keys() method

2013-10-06 Thread Guido van Rossum
Guido van Rossum added the comment: No time to follow this in detail, but one thing: please do not make the selector appear "false" under *any* circumstances. I've seen too many code write "if foo" where they meant "if foo is not None" and get in trouble because foo wasn't None but happened to

[issue19172] selectors: add keys() method

2013-10-06 Thread STINNER Victor
STINNER Victor added the comment: 2013/10/6 Charles-François Natali : >> BaseSelector.register(fd) raises a KeyError if fd is already registered, >> which means that any selector must know the list of all registered FDs. For >> EpollSelector, the list may be inconsistent *if* the epoll is objec

[issue19172] selectors: add keys() method

2013-10-06 Thread Charles-François Natali
Charles-François Natali added the comment: > BaseSelector.register(fd) raises a KeyError if fd is already registered, > which means that any selector must know the list of all registered FDs. For > EpollSelector, the list may be inconsistent *if* the epoll is object is > modified externally, b

[issue19172] selectors: add keys() method

2013-10-06 Thread STINNER Victor
STINNER Victor added the comment: BaseSelector.register(fd) raises a KeyError if fd is already registered, which means that any selector must know the list of all registered FDs. For EpollSelector, the list may be inconsistent *if* the epoll is object is modified externally, but it's really a

[issue19172] selectors: add keys() method

2013-10-05 Thread Charles-François Natali
Charles-François Natali added the comment: > If you want to unregister while iterating on .keys(), just copy .keys(), as > I do when removing items from a list or a dict while iterating on it. Of course, but as noted by Antoine, it makes the return type dependent of an implementation detail (I d

[issue19172] selectors: add keys() method

2013-10-05 Thread STINNER Victor
STINNER Victor added the comment: Using .keys() to test if the selector is empty is surprising. To test if a str, list, tuple, dict, set, ..., is empty: if container: is enough. Or sometimes I write if len(container): ... Selector has no length? -- ___

[issue19172] selectors: add keys() method

2013-10-05 Thread Antoine Pitrou
Antoine Pitrou added the comment: Indeed it's easy enough to call list() or set() on the result if you need it. On the other hand, the problem with returning a dict view is that it makes the return type dependent on an implementation detail. Returning a simple iterator would be great, except t

[issue19172] selectors: add keys() method

2013-10-05 Thread STINNER Victor
STINNER Victor added the comment: If you want to unregister while iterating on .keys(), just copy .keys(), as I do when removing items from a list or a dict while iterating on it. -- ___ Python tracker

[issue19172] selectors: add keys() method

2013-10-05 Thread Charles-François Natali
New submission from Charles-François Natali: This adds a keys() method to selectors, to return all the registered keys. It's useful, because one often needs to loop until all registered file objects have been unregistered e.g. (inspired from subprocess, see #18923): while selector.keys(): fo