Inada Naoki added the comment:
I close this issue because Reversible ABC was added.
It's sad that Sequnce.__reversed__ is just makes reversed() slow without any
benefit.
But removing it without breaking backward compatibility is not easy for now.
--
resolution: -> wont fix
stage:
INADA Naoki added the comment:
__contains__ is required for Container.
So there is a clear reason to define it.
Additionaly,
http://docs.python.org/3.3/reference/datamodel.html#object.__contains__
doesn't discourage to implement slower pure-python method.
In case of __reversed__, I can't find
Raymond Hettinger added the comment:
Guido put a number of non-optimal implementations in the ABCs. His goal was to
define the interface and to supply a working default implementation (see
MutableMapping.clear() for a prime example).
In the case of __reversed__(), it is unfortunate that it
Nick Coghlan added the comment:
This sounds like a legitimate complaint to me, as the one in the ABC will be at
least marginally slower in CPython since it's written in Python while reversed
uses a builtin C implementation.
Classing it as an enhancement rather than a behavioural bug though,
Nick Coghlan added the comment:
The observation about it incorrectly flagging __reversed__ as an expected
method for Sequence objects is also valid.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16712
Terry J. Reedy added the comment:
I would expect that the default method of reversed() and
collections.abc.Sequence.__reverse__ are more or less the same. If so, this
should be closed as invalid. But I want to hear from the abc experts.
--
nosy: +rhettinger, stutzbach, terry.reedy
INADA Naoki added the comment:
I believe that using Sequence ABC as mix-in is recommended when implementing
custom sequence.
But mixing-in it violates should only provide __reversed__() if they can
provide an implementation that is more efficient than the one
provided by reversed().
New submission from INADA Naoki:
http://docs.python.org/3.3/reference/datamodel.html#object.__reversed__
Objects that support the sequence protocol should only provide
__reversed__() if they can provide an implementation that is more efficient
than the one provided by reversed().