This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author abarnert
Recipients abarnert, abarry, curioswati, gvanrossum, martin.panter, ncoghlan, r.david.murray, rhettinger, serhiy.storchaka, terry.reedy
Date 2016-01-04.19:53:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1451937190.97.0.351759853555.issue25864@psf.upfronthosting.co.za>
In-reply-to
Content
> IMO allowing any special method to be set to None seems to make more trouble than it is worth. 

That's exactly why allowing _any_ special method to be None is a separate issue (#25958). Most special methods don't have any corresponding problem to the one with __reversed__.

> Ideally I think it would be better to require __reversed__() for reverse() to work, but such a change would break compatibility.

See the -ideas thread "Deprecating the old-style sequence protocol" (http://article.gmane.org/gmane.comp.python.ideas/37588).

> Regarding test_enumerate.py, your class looks like this:

Please look at the two classes directly above it in the same function. The new Blocked exactly parallels the existing NoLen.

> I suggest either remove __getitem__() if it serves no purpose

It very definitely serves a purpose. The whole point of the new test is that reversed will not fall back to using __getitem__ and __len__ if __reversed__ is None. So __getitem__ has to be there; otherwise, we already know (from the NoGetItem test) that it wouldn't get called anyway.

This is exactly the same as the NoLen test, which verifies that __reversed__ will not fall back to __getitem__ and __len__ if one is present but not both.

> , or change it to something like this if you really want an unreversible sequence:

Sure, if I wanted a real class that could be used as a sequence but could not be reversed. But all I want here is a toy class for testing the specific method lookup behavior. Again, exactly like the existing classes in the same test.

Finally, from your previous comment:

> I think the ABC documentation should clarify which methods are checked for None and which aren’t. 

Looking at this a bit more: The ABC documentation doesn't even tell you that, e.g., Container and Hashable have subclass hooks that automatically make any class with __contains__ and __hash__ act like registered subclasses while, say, Sequence and Set don't. So, you're suggesting that we should explain where the hooks in some of those types differ, when we haven't even mentioned where the hooks exist at all. Maybe collections.abc _should_ have more detail in the docs, but I don't think that should be part of this bug. (Practically, I've always found the link to the source at the top sufficient--trying to work out exactly why tuple meets some ABC and some custom third-party sequence doesn't, which is a pretty rare case to begin with, is also pretty easy to deal with: you scan the source, quickly find that Sequence.register(tuple), read up on what it does, and realize that collections.abc.Sequence.register(joeschmoe.JoeSchmoeSequence) is what you want, and you're done.)
History
Date User Action Args
2016-01-04 19:53:11abarnertsetrecipients: + abarnert, gvanrossum, rhettinger, terry.reedy, ncoghlan, r.david.murray, martin.panter, serhiy.storchaka, abarry, curioswati
2016-01-04 19:53:10abarnertsetmessageid: <1451937190.97.0.351759853555.issue25864@psf.upfronthosting.co.za>
2016-01-04 19:53:10abarnertlinkissue25864 messages
2016-01-04 19:53:10abarnertcreate