[issue16712] collections.abc.Sequence should not provide __reversed__

2019-04-11 Thread Inada Naoki


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: needs patch -> resolved
status: open -> closed
versions: +Python 3.8 -Python 3.4

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16712] collections.abc.Sequence should not provide __reversed__

2012-12-25 Thread INADA Naoki

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 a reason to require it and
reference discourage it explicitly.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16712
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16712] collections.abc.Sequence should not provide __reversed__

2012-12-23 Thread Raymond Hettinger

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 slows down the default 
implementation of reverse().  The latter only runs faster because it is in C, 
not because of any algorithmic issue.

FWIW, the same is also true of Sequence.__contains__().  This logic in the ABC 
is straight-forward but slows down the code as compared to Python's C 
optimizations which can infer a __contains__ method from a sequence that 
defines __getitem__().

Given that the issue isn't algorithmic and is merely a C vs pure Python 
issue, I recommend leaving the current code as-is.

If someone truly cares about the speed issue, it would be an easy matter to 
supply a C helper function in the ABCs for speeding-up __reversed__ and 
__contains__ (for an example of how to do this, see _count_elements() in the 
collections module).

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16712
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16712] collections.abc.Sequence should not provide __reversed__

2012-12-22 Thread Nick Coghlan

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, as what we 
have now isn't *wrong*, it's just not optimal.

--
nosy: +ncoghlan
stage:  - needs patch
type:  - enhancement

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16712
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16712] collections.abc.Sequence should not provide __reversed__

2012-12-22 Thread Nick Coghlan

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
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16712] collections.abc.Sequence should not provide __reversed__

2012-12-21 Thread Terry J. Reedy

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
versions:  -Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16712
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16712] collections.abc.Sequence should not provide __reversed__

2012-12-21 Thread INADA Naoki

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().


Defining __reversed__ in Sequence ABC also means that classes doesn't have
__reversed__ aren't Sequence. While not implementing it is recommended
for most cases.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16712
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue16712] collections.abc.Sequence should not provide __reversed__

2012-12-18 Thread INADA Naoki

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().

collections.abc.Sequence can't provide more efficient method.
It only make `reversed()` slower.

--
components: Library (Lib)
messages: 177688
nosy: naoki
priority: normal
severity: normal
status: open
title: collections.abc.Sequence should not provide __reversed__
versions: Python 3.4, Python 3.5

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16712
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com