Re: [Python-Dev] Is explicit registration of Iterators needed?

2016年10月07日 15:56:09 -0700

On 7 October 2016 at 17:08, Guido van Rossum <[email protected]> wrote:
> On Fri, Oct 7, 2016 at 7:47 AM, Serhiy Storchaka <[email protected]>
> wrote:
> > On 07.10.16 17:37, Guido van Rossum wrote:
> >>
> >> On Fri, Oct 7, 2016 at 6:36 AM, Serhiy Storchaka <[email protected]>
> >> wrote:
> >>>
> >>> A number of builtin iterator classes (but not all builtin iterator
> >>> classes)
> >>> are registered with the Iterator ABC in Lib/_collections_abc.py. But
> >>> isinstance(it, Iterable) check works without explicit registration,
> >>> because
> >>> Iterable has __subclasshook__ that checks iterator methods. Is there a
> >>> need
> >>> in explicit registrations? Or their can be safely removed?
> >>
> >>
> >> The preferred apprach is actually inheritance; registration comes
> >> next; the __subclasshook__ is a final compromise to the tradition of
> >> duck typing. I think the registrations should stay.
>
I have a question about the registration of builtins. Currently, typing.py
contains this line:
 ByteString.register(type(memoryview(b'')))
But there are two test lines in test_collections.py
 self.assertNotIsInstance(memoryview(b""), ByteString)
 self.assertFalse(issubclass(memoryview, ByteString))
This looks like a contradiction. Which one is right?
Should these tests be removed or the registration in typing.py?
--
Ivan
_______________________________________________
Python-Dev mailing list
[email protected]
https://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to