[issue25864] collections.abc.Mapping should include a __reversed__ that raises TypeError

Andrew Barnert report at bugs.python.org
Mon Dec 28 15:38:44 EST 2015


Andrew Barnert added the comment:

The attached patch does the following:

* collections.abc.Mapping.__reversed__ = None.

* collections.abc.Iterable.__subclasshook__ checks for None the same way Hashable does:

  * This tests for any falsey value, not just None. I'm not sure this is ideal, but it's consistent with Hashable, and it's unlikely to ever matter.

  * The test will only block implicit subclassing. If a class, e.g., inherits from tuple (which is explicitly registered with Sequence, which inherits from Iterable), it's Iterable, even if it sets __iter__ = None. I think this is the right behavior, and it's consistent with Hashable.

* iter and reversed add checks for None, which raise a TypeError with the appropriate message (instead of "'NoneType' is not callable").

* datamodel.rst section "Special method names" includes a paragraph on setting special methods to None.

* Tests for changes to reversed (in test_enumerate.py), iter (in test_iter.py), Iterable (in test_collections.py), and Mapping (in collections.py).

----------
keywords: +patch
Added file: http://bugs.python.org/file41440/cpython-iter-patch.diff

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25864>
_______________________________________


More information about the Python-bugs-list mailing list