[Python-Dev] what is a dict_keys and where can I import it from? (original) (raw)

Amaury Forgeot d'Arc amauryfa at gmail.com
Tue Feb 12 12:38:48 CET 2013


2013/2/12 Steven D'Aprano <steve at pearwood.info>

An anomaly, which I cannot explain:

py> issubclass(type(keys), KeysView) True py> type(keys) is KeysView False py> type(keys).mro (<class 'dictkeys'>, <class 'object'>)

This disturbs my calm, because I expect that if issubclass returns True, the two classes will either be identical, or the second will be in the MRO of the first. What have I missed?

Ah, the magic of ABCs... KeysView overrides instancecheck, and can pretend to be any other class.

This is precisely set in Lib/collections/abc.py: KeysView.register(dict_keys)

-- Amaury Forgeot d'Arc -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20130212/94dba57a/attachment.html>



More information about the Python-Dev mailing list