New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change names of builtin types exposed in the types module #100129
Comments
It sounds like a good idea. Changing names like builtin_function_or_method will impact doctests, but I think that it's worth it. |
+1 to this idea. This will make life easier for tools that do dynamic inspection of Python at runtime. The current situation makes life difficult at times for, e.g., mypy's stubtest tool. |
I proposed this idea several years ago, and perhaps even an issue was created (but I cannot find it now). Guido was positive about this, but I had some doubts. The original code was written in 2018, now I'm going to finish it. |
Changing the names of common types like There must be other ways to make these objects pickleable. |
Yes, it will break some doctests. The main purpose of this change is not making these types pickleable (a special case was already added for The breakage of doctests can be reduced if we omit the module name in repr and error messages if |
…ns (pythonGH-100142) (cherry picked from commit b98d2d3) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
…ns (pythonGH-100142) (cherry picked from commit b98d2d3) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka commentedDec 9, 2022
•
edited by bedevere-bot
Some builtin types (like
int
,range
,map
) are exposed in thebuiltins
module under their names.int.__name__
is "int" andint.__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 thetypes
module. 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 thetypes
modules so that they will match names under which they are accessible.Linked PRs
The text was updated successfully, but these errors were encountered: