Some builtin types (like int, range, map) are exposed in the builtins module under their names. int.__name__ is "int" and int.__module__ is "builtins". getattr(sys.modules[int.__module__], int.__name__) is int
Other builtin types are exposed in the types module, but their __module__ attribute is still "builtins", and their __name__ attribute is different from the name under which they are accessible in the types module. The relation between names is not obvious, when you see <class 'builtin_function_or_method'>, it is hard to defer that it is types.BuiltinFunctionType.
As result, these types cannot be pickled:
>>> pickle.dumps(types.ClassMethodDescriptorType)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
_pickle.PicklingError: Can't pickle <class 'classmethod_descriptor'>: attribute lookup classmethod_descriptor on builtins failed
I propose to change attributes __module__, __name__ and __qualname__ of all builtin types exposed in the types modules so that they will match names under which they are accessible.
Linked PRs
Some builtin types (like
int,range,map) are exposed in thebuiltinsmodule under their names.int.__name__is "int" andint.__module__is "builtins".getattr(sys.modules[int.__module__], int.__name__) is intOther builtin types are exposed in the
typesmodule, but their__module__attribute is still "builtins", and their__name__attribute is different from the name under which they are accessible in thetypesmodule. The relation between names is not obvious, when you see<class 'builtin_function_or_method'>, it is hard to defer that it istypes.BuiltinFunctionType.As result, these types cannot be pickled:
I propose to change attributes
__module__,__name__and__qualname__of all builtin types exposed in thetypesmodules so that they will match names under which they are accessible.Linked PRs