Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix object.__reversed__ doc #50284

Closed
terryjreedy opened this issue May 16, 2009 · 2 comments
Closed

Fix object.__reversed__ doc #50284

terryjreedy opened this issue May 16, 2009 · 2 comments
Assignees
Labels
docs Documentation in the Doc dir

Comments

@terryjreedy
Copy link
Member

BPO 6034
Nosy @birkenfeld, @terryjreedy

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/birkenfeld'
closed_at = <Date 2009-05-16.11:13:35.522>
created_at = <Date 2009-05-16.03:18:06.635>
labels = ['docs']
title = 'Fix object.__reversed__ doc'
updated_at = <Date 2009-05-16.11:13:35.520>
user = 'https://github.com/terryjreedy'

bugs.python.org fields:

activity = <Date 2009-05-16.11:13:35.520>
actor = 'georg.brandl'
assignee = 'georg.brandl'
closed = True
closed_date = <Date 2009-05-16.11:13:35.522>
closer = 'georg.brandl'
components = ['Documentation']
creation = <Date 2009-05-16.03:18:06.635>
creator = 'terry.reedy'
dependencies = []
files = []
hgrepos = []
issue_num = 6034
keywords = []
message_count = 2.0
messages = ['87852', '87878']
nosy_count = 2.0
nosy_names = ['georg.brandl', 'terry.reedy']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue6034'
versions = ['Python 2.6', 'Python 3.0', 'Python 3.1', 'Python 2.7', 'Python 3.2']

@terryjreedy
Copy link
Member Author

3.3.5. Emulating container types
object.__reversed__(self)
says in 3.0 and 3.1 and I assume in 2.x:
"Objects should normally only provide __reversed__() if they do not
support the sequence protocol and an efficient implementation of reverse
iteration is possible."

The builtin sequences violate this because because they do support the
sequence and have __ reversed__ methods anyway. And iterables that do
not support that protocol obviously *must* provide a method to be
reverse iterable.

I believe the point is that it is hard for Python code to beat the
C-coded version of the obvious

def __reversed__(self):
   for i in reversed(range(self.__len__)):
      yield self.__getitem__(i)

So I think the entry should say: "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()." possibly followed by "Objects that do not supposrt the
sequence protocol must provide __reversed__ to be reverse iterable."

@terryjreedy terryjreedy added the docs Documentation in the Doc dir label May 16, 2009
@birkenfeld
Copy link
Member

Thanks, fixed in r72675.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs Documentation in the Doc dir
Projects
None yet
Development

No branches or pull requests

2 participants