[docs] [issue27544] Document the ABCs for instance/subclass checks of dict view types

Terry J. Reedy report at bugs.python.org
Fri Jul 22 16:28:14 EDT 2016


Terry J. Reedy added the comment:

The view objects *are* built-ins, but are not exposed in the __builtins__ module.  This is true of many internal types, perhaps even a majority. The function and list_iterator classes are other examples.

>>> type(lambda: 0)
<class 'function' at 0x0000000054B038B0>
>>> type(iter([]))
<class 'list_iterator' at 0x0000000054B05A60>

A few such 'hidden' classes are exposed in the types module.

"This module provides names for many of the types that are required to implement a Python interpreter. It deliberately avoids including some of the types that arise only incidentally during processing such as the listiterator type.

Typical use of these names is for isinstance() or issubclass() checks."

The function class is.

"types.FunctionType
types.LambdaType

    The type of user-defined functions and functions created by lambda expressions."
  
The list_iterator class is not. Perhaps the rationale is that there is no reason to know whether an iterator is iterating over a list, tuple, range, set, frozenset, dict, or anything else.  They are all used the same.  On the other hand, Different view types are used a bit differently.

Types includes a generic MappingProxyType.  Perhaps you should propose adding the specific dict view types.  Or you can create them yourself.
  KeysViewType = type({}.keys())
  ValuesViewType = type({}.values())
  ItemsViewType = type({}.items())
This is the code that would be used in the module if they were added there.

----------
nosy: +terry.reedy
versions:  -Python 3.2, Python 3.3, Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27544>
_______________________________________


More information about the docs mailing list