Message257481
| Author |
gvanrossum |
| Recipients |
abarnert, gvanrossum, martin.panter, ncoghlan, r.david.murray, serhiy.storchaka |
| Date |
2016年01月04日.19:22:04 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1451935324.29.0.840363611808.issue25958@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
I propose to solve the narrow problem by indeed supporting the setting of certain special methods to None similar to __hash__. This should be limited to those methods for which this adds value, e.g. where the complete absence of the method causes a fall-back to a different API (e.g. __getitem__+__len__ in the case of __reversed__) -- the None value should just block the fallback. This will require some changes in the ABCs that test for the presence of a given method (Iterable/__iter__, Container/__contains__, Reversible/__reversed__ -- the latter ABC should be added) and in implementations such as reversed(), iter() and 'in'. Maybe we should just do this for every ABC in collections.abc (plus Reversible) that has a __subclasshook__ that tests for the presence of the special method.
Oh, probably some more, like Iterator/__next__, Sized/__len__ and Callable/__call__. But for those there isn't a fallback in the corresponding bytecode, so I'm only +0 for those -- it doesn't seem to harm anything to be consistent with those for which it does matter, but it doesn't cost much either, and the consistency is slightly useful -- it provides a pattern to follow for future ABCs. |
|