[Python-ideas] Adding collections.abc.Ordered

Guido van Rossum guido at python.org
Sat Dec 26 21:17:45 EST 2015


On Sat, Dec 26, 2015 at 5:09 PM, Serhiy Storchaka <storchaka at gmail.com>
wrote:

> On 27.12.15 01:05, Guido van Rossum wrote:
>
>> There is a precedent for declaring that a method isn't implemented:
>> __hash__. The convention is to set it to None in the subclass that
>> explicitly doesn't want to implement it. The __subclasshook__ in
>> collections.Hashable checks for this. The pattern is also used for
>> __await__.
>>
>
> Yes, this was the first thing that I tried, but it doesn't work, as shown
> in my example in issue25864. This is yet one thing that should be fixed in
> Reversible.
>

Yeah, sorry, I didn't mean it already works. I just meant that we should
adopt the same convention here.


> May be we have to use this idiom more widely, and specially handle
> assigning special methods to None. The error message "'sometype' can't be
> reverted" looks better than "'NoneType' is not callable".
>

Yes, that's what I'm proposing. Just like hash() says "TypeError:
unhashable type: 'list'" instead of "TypeError: 'NoneType' object is not
callable" or "AttributeError: 'list' object has no attribute '__hash__'".

-- 
--Guido van Rossum (python.org/~guido)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151226/e9152173/attachment.html>


More information about the Python-ideas mailing list