Python 3.1 - DictType not part of type module?

This is what I found in my install of Python 3.1 on Windows.

Where can I find other types, in particular DictType and StringTypes?

>>> print('\n'.join(dir(types))) BuiltinFunctionType BuiltinMethodType CodeType FrameType FunctionType GeneratorType GetSetDescriptorType LambdaType MemberDescriptorType MethodType ModuleType TracebackType __builtins__ __doc__ __file__ __name__ __package__ >>> 
+4
source share
2 answers

According to the types module document ( http://docs.python.org/py3k/library/types.html ),

This module defines names for some types of objects that are used by the standard Python interpreter, but are not displayed as embedded, such as int or str ....

Typical uses for isinstance() or issubclass() checks.

Since the type of the dictionary can be used with dict , there is no need to enter such a type in this module.

 >>> isinstance({}, dict) True >>> isinstance('', str) True >>> isinstance({}, str) False >>> isinstance('', dict) False 

(The examples on int and str also deprecated.)

+7
source

Grepping / usr / lib / python3.1 for 'DictType' shows that its only appearance is in /usr/lib/python3.1/lib2to3/fixes/fix_types.py . There _TYPE_MAPPING displays a DictType in a dict .

 _TYPE_MAPPING = { 'BooleanType' : 'bool', 'BufferType' : 'memoryview', 'ClassType' : 'type', 'ComplexType' : 'complex', 'DictType': 'dict', 'DictionaryType' : 'dict', 'EllipsisType' : 'type(Ellipsis)', #'FileType' : 'io.IOBase', 'FloatType': 'float', 'IntType': 'int', 'ListType': 'list', 'LongType': 'int', 'ObjectType' : 'object', 'NoneType': 'type(None)', 'NotImplementedType' : 'type(NotImplemented)', 'SliceType' : 'slice', 'StringType': 'bytes', # XXX ? 'StringTypes' : 'str', # XXX ? 'TupleType': 'tuple', 'TypeType' : 'type', 'UnicodeType': 'str', 'XRangeType' : 'range', } 

So, I think in Python3 DictType is replaced by dict .

+1
source

All Articles