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, r.david.murray, rhettinger
Date 2015-12-17.05:45:58
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1450331159.43.0.971195697332.issue25864@psf.upfronthosting.co.za>
In-reply-to
Content
@R. David Murray:

> What is it that makes reversed raise a typeerror on dict here?

There are separate slots for tp_as_sequence and tp_as_mapping, so a C type can be (and generally is) one or the other, not both. 

But for Python types, anything that has __getitem__ is both a sequence and a mapping at the C level. (It's one of the few minor inconsistencies between C and Python types left, like having separate slots for nb_add and sq_concat in C but only __add__ for both in Python.)

> Not that we can change it at this point, but reversed blindly using len and __getitem__ for user classes but not on dict is rather inconsistent.  

But it's consistent with iter blindly using __len__ and __getitem__ if __iter__ is not present on Python classes but not doing that on C classes. That's how "old-style sequences" work, and I don't think we want to get rid of those (and, even if we did, I'm pretty sure that would require at least a thread on -dev or -ideas...).

> I suppose the dict TypeError special case catches common mistakes?

Yes. That's probably not why it was implemented (it's easier for a C type to _not_ fake being a broken sequence than to do so), but it has that positive effect.

> In which case adding a __reversed__ that raises a TypeError to Mapping seems to make sense for the same reason.

Exactly.

I think Raymond's point is that, while it does make sense, it may still not be important enough to be worth even two lines of code. Hopefully we can get more than two opinions (his and mine) on that question; otherwise, at least as far as I'm concerned, he trumps me.
History
Date User Action Args
2015-12-17 05:45:59abarnertsetrecipients: + abarnert, rhettinger, r.david.murray, abarry, curioswati
2015-12-17 05:45:59abarnertsetmessageid: <1450331159.43.0.971195697332.issue25864@psf.upfronthosting.co.za>
2015-12-17 05:45:59abarnertlinkissue25864 messages
2015-12-17 05:45:58abarnertcreate