[Python-ideas] Improve ABCs _dump_registry() readability

Guido van Rossum guido at python.org
Sun Dec 31 12:54: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.

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.

I guess a PR to fix the registry output would make sense (first file a bug
on bugs.python.org for it).

On Sat, Dec 30, 2017 at 11:19 PM, Yahya Abou 'Imran via Python-ideas <
python-ideas at python.org> wrote:

> In python 2.7, ABCs's caches and registries are sets. But in python 3.6
> they are WeakSet.
> In consequence, the output of _dump_registry() is almost useless:
>
> >>> from collections import abc
> >>> abc.Iterator._dump_registry()
> Class: collections.abc.Iterator
> Inv.counter: 40
> _abc_cache: <_weakrefset.WeakSet object at 0x7f4b58fe2668>
> _abc_negative_cache: <_weakrefset.WeakSet object at 0x7f4b53283780>
> _abc_negative_cache_version: 40
> _abc_registry: <_weakrefset.WeakSet object at 0x7f4b58fe2630>
>
> We could convert them into a regular set before printing:
>
> if isinstance(value, WeakSet):
>     value = set(value)
>
> The result:
>
> >>> abc.Iterator._dump_registry()
> Class: collections.abc.Iterator
> Inv.counter: 40
> _abc_cache: {<class 'dict_valueiterator'>, <class 'bytearray_iterator'>,
> <class 'tuple_iterator'>, <class 'dict_itemiterator'>, <class
> 'dict_keyiterator'>, <class 'str_iterator'>, <class 'zip'>, <class
> 'set_iterator'>, <class 'list_reverseiterator'>, <class 'range_iterator'>,
> <class 'longrange_iterator'>, <class 'list_iterator'>, <class
> 'bytes_iterator'>}
> _abc_negative_cache: set()
> _abc_negative_cache_version: 40
> _abc_registry: set()
>
>
> NB: It seems pretty weird to me that registry is empty... All the
> iterators in the cache should've been in the registry instead, should'nt
> they?
> _______________________________________________
> 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/
>



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


More information about the Python-ideas mailing list