Message257512
| Author |
abarnert |
| Recipients |
abarnert, gvanrossum, martin.panter, ncoghlan, r.david.murray, serhiy.storchaka |
| Date |
2016年01月05日.02:28:37 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1451960924.25.0.119443468167.issue25958@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
Is an hg export patch usable? If not, let me know and I'll flatten it.
Anyway, the attached patch fixes #25987 and #25864 as well as this one, as follows:
* Every ABC in collections.abc that has a subclass hook now treats None as blocking, instead of a few checking falsiness and others not checking anything. (And all the hooks are now identical, which eliminates any unintended inconsistencies.)
* collections.abc.Mapping.__reversed__ = None (fixes #25864).
* collections.abc.Reversible added (fixes #25987).
* iter(), reversed(), and in operator all have custom text in their TypeError instead of the generic "'NoneType' object is not callable".
* Unit tests for all of the above, plus that None blocking also works appropriately (i.e., same as in CPython 2.3-3.6) for __spam__ -> __rspam__, __ispam__ -> __spam__.
* I didn't try to write tests for _everything_ with fallback. For example, blocking fallback from __str__ to __repr__, or anything to do with __*attr*__, does work, but I can't think of any conceivable case where you'd ever do such a thing. (The fact that you can write a class that isn't repr-able isn't a feature of Python we want to guarantee, it's just a side-effect of other stuff that will hopefully never come up, so it seems wrong to write a unit test to guarantee it.)
* Data Model docs document that you can set a special method to None to block behavior (including blocking fallback to old-style sequence protocol, inheritance from superclass, etc.).
(Note that this patch is not yet fully tested, because my Windows and Cygwin builds are for some reason taking forever. But if I don't post an update tomorrow, that will mean they passed the overnight tests. I doubt anyone was going to commit this tonight anyway, but, just in case...) |
|