[Python-ideas] Improve ABCs _dump_registry() readability
Yahya Abou 'Imran
yahya-abou-imran at protonmail.com
Sun Dec 31 13:24:17 EST 2017
>Yeah, I guess few developers have needed to use _dump_registry(), and also it's easy enough to just access e.g. Iterator._abc_registry yourself.
>
Yes, I saw that it's not well-known. I was studying hard the internals of ABCs and ABCMeta, so I end up using it and modifying it.
>The reason Iterator._abc_registry is empty is that no class directly registered with it -- they are all registered with e.g. Sequence. The cache includes classes registered with subclasses, but the registry itself does not.
No, in the source code they are!
in _collections_abc.py, just after Iterator definition:
Iterator.register(bytes_iterator)
Iterator.register(bytearray_iterator)
#Iterator.register(callable_iterator)
Iterator.register(dict_keyiterator)
Iterator.register(dict_valueiterator)
Iterator.register(dict_itemiterator)
Iterator.register(list_iterator)
Iterator.register(list_reverseiterator)
Iterator.register(range_iterator)
Iterator.register(longrange_iterator)
Iterator.register(set_iterator)
Iterator.register(str_iterator)
Iterator.register(tuple_iterator)
Iterator.register(zip_iterator)
For some reason, the register is being cleared at some point.
I tried:
Iterator.register(bytes_iterator)
Iterator._dump_registry(open('iterator_registry.log', 'w'))
Iterator.register(bytearray_iterator)
.
.
.
And I got:
$ cat iterator_registry.log
Class: collections.abc.Iterator
Inv.counter: 8
_abc_cache: {<class 'bytes_iterator'>}
_abc_negative_cache: set()
_abc_negative_cache_version: 8
_abc_registry: set()
It's going into the cache and not into the registry.
Strange behaviour...
>I guess a PR to fix the registry output would make sense (first file a bug on bugs.python.org for it).
Ok, I will!
More information about the Python-ideas
mailing list