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 don't think there's any other place in the stdlib where a dict view is returned). > Using .keys() to test if the selector is empty is surprising. To test if a > str, list, tuple, dict, set, ..., is empty: if container: <not empty> is > enough. > > Or sometimes I write if len(container): ... > > Selector has no length? No. For example, select.epoll objects don't have a length either. I'm not sure whether selectors have a natural length: if we added a __len__, we should also add __iter__ and IMO a selector isn't a container. Returning all the keys is a generic method that can be useful besides checking that the selector has registered keys. > So perhaps two methods are needed: > - a keys() method returning an iterator > - a has_keys() method returning a boolean Sounds a bit overkill, no? keys() is definitely usful, and I'm not sure that it'll actually be a performance bottleneck in practice. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue19172> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com