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?
On Fri, Oct 7, 2016 at 6:36 AM, Serhiy Storchaka <storchaka@gmail.com> 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. -- --Guido van Rossum (python.org/~guido)
On 07.10.16 17:37, Guido van Rossum wrote:
On Fri, Oct 7, 2016 at 6:36 AM, Serhiy Storchaka <storchaka@gmail.com> 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.
Should we register missed builtin iterators? For example longrange_iterator.
On Fri, Oct 7, 2016 at 7:47 AM, Serhiy Storchaka <storchaka@gmail.com> wrote:
On 07.10.16 17:37, Guido van Rossum wrote:
On Fri, Oct 7, 2016 at 6:36 AM, Serhiy Storchaka <storchaka@gmail.com> 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.
Should we register missed builtin iterators? For example longrange_iterator.
I don't feel strongly about this either way. Let sleeping dogs lie, etc. (Is this related to issue 26906?) -- --Guido van Rossum (python.org/~guido)
On 7 October 2016 at 17:08, Guido van Rossum <guido@python.org> wrote:
On Fri, Oct 7, 2016 at 7:47 AM, Serhiy Storchaka <storchaka@gmail.com> wrote:
On 07.10.16 17:37, Guido van Rossum wrote:
On Fri, Oct 7, 2016 at 6:36 AM, Serhiy Storchaka <storchaka@gmail.com> 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
On Fri, Oct 7, 2016 at 3:52 PM, Ivan Levkivskyi <levkivskyi@gmail.com> wrote:
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?
Looks like the registration is in error. The stubs (and hence mypy) don't consider memoryview consistent with ByteString. -- --Guido van Rossum (python.org/~guido)
On 07.10.16 18:08, Guido van Rossum wrote:
On Fri, Oct 7, 2016 at 7:47 AM, Serhiy Storchaka <storchaka@gmail.com> wrote:
Should we register missed builtin iterators? For example longrange_iterator.
I don't feel strongly about this either way. Let sleeping dogs lie, etc. (Is this related to issue 26906?)
Not directly. If remove explicit iterator registrations some tests become failing due to the bug 26906. After fixing issue26906 the tests are passed again. Thus the bug 26906 could be found earlier if iterators were not registered.
participants (3)
-
Guido van Rossum
-
Ivan Levkivskyi
-
Serhiy Storchaka