[Python-ideas] Adding collections.abc.Ordered
Wes Turner
wes.turner at gmail.com
Sat Dec 26 19:34:05 EST 2015
* collections.abc.Ordered
* collections.abc.Reversible
* collections.abc.Infinite [...]
* collections.abc.Sorted ?
On Dec 26, 2015 7:24 PM, "Andrew Barnert via Python-ideas" <
python-ideas at python.org> wrote:
> On Dec 26, 2015, at 16:09, 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.
>
> As Guido pointed out in your typehinting #170, that isn't a bug with
> typing.Reversible. You can't use typing types in runtime type tests with
> issubclass. That isn't supposed to work, and the fact that it often kind of
> does work is actually a bug that he's fixing. So the fact that it doesn't
> work in this case is correct.
>
> That also means your attempted solution to this thread is wrong;
> typing.Reversible cannot be used as a substitute for
> collections.abc.Ordered.
>
> > 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".
>
> I agree with this. A new collections.abc.Reversible (interposed between
> Iterable and Sequence) would be a potential substitute for Ordered, and
> would have this problem, which would be solvable by treating __reversed__ =
> None specially, just like __hash__ = None. And I'm pretty sure it would
> come up in practice (see issue 25864). And once we've got two or three
> special methods doing this instead of one, making it more general does
> sound like a good idea. So, if we need Reversible as a substitute for
> Ordered, then I think we want the general "is None" test.
>
> But I'm still not sure Reversible is a good substitute for Ordered (again,
> consider an infinitely long collection, or just a lazy proxy that doesn't
> compute values until needed and doesn't know its length in advance--they're
> clearly ordered, and just as clearly not reversible), and I'm not sure we
> actually need either Reversible or Ordered in the first place.
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20151226/38eb9fde/attachment.html>
More information about the Python-ideas
mailing list