-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
type(None).__module__ returns wrong module #128197
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
Comments
Hello! Line 3336 in c5b0c90
|
@Eclips4 It's tot about |
Oh, yes, I've misread your message. What made you think that |
WDYM >>> from builtins import NoneType
Traceback (most recent call last):
File "<python-input-3>", line 1, in <module>
from builtins import NoneType
ImportError: cannot import name 'NoneType' from 'builtins' (unknown location)
>>> from types import NoneType
>>> print(NoneType)
<class 'NoneType'> |
That's doesnt mean that Lines 2119 to 2158 in d61542b
Why do you see Line 1418 in d61542b
This is a long-standing behavior and I don't think we should change it. |
NoneType was introduced in 3.10, so not that long, and #63637 says it was in types. How about adding an alias for compatibility? |
|
@Eclips4 I'm getting a feeling you're being dismissive towards me.
I don't have a problem with builtins in |
Sorry, I just didn't understand you previously. I didn't mean to be dismissive or offend you. I now understand your confusion and summarize our conversation for others: |
Changing it to Concerning the other builtins, their actual class name is usually different from the exposed name in |
Would moving it to this would work from types import NoneType
from builtins import NoneType this would break assert type(None).__module__ == 'builtins' |
I don't think so because some code might categorize builtins using By the way, I'd like to know the use case of having cc @JelleZijlstra for another opinion (maybe) |
OTOH, |
I don't mind which module it is in, as long it's consistent. It would simplify all code that relies on it. My use case is a code generator. For simple cases I can do |
Can you elaborate? For us humans anything goes, but when any metaprogramming or introspection is involved, it's just another special case to handle. I don't see any practical about it. |
All objects have a type but some types are special and not exposed as "global" names. The Now, yes, it's special-casing, but this has been a longstanding behaviour. We do not (likely) want to expose globally the type of None, namely we don't want to be able to write something like While it's a special case, I'm not sure that changing it would work. Unless we expose them in Concerning the introspection tools, I think they should deal with it. At least, in Sphinx, we do (https://github.com/sphinx-doc/sphinx/blob/e18155fa106cf64d7b39dcc6506b60fd82703b10/sphinx/util/typing.py#L41) but this is not really hard to maintain. We know this discrepency but I think the standard library can put the burden of this on the tools. I'm actually unusure of whether the interpreter would still work properly if we were to actually change the module name of built-in types such as functions or |
OK, bringing those types to I agree it's not a huge problem, and even if it's awkward, it doesn't hit a large part of the user base. I can't imagine reasonable code that would rely on Then again, I've been surprised before, and I know not all code is reasonable. |
There are a bunch of baseline types whose names are not directly exposed in the Lines 13 to 16 in 29caec6
Lines 327 to 332 in 29caec6
All of those types list "builtins" as the module because they are "builtins" as a concept and needed some module name as the And adding anything to As such, I'm closing the issue as "won't fix". |
I do actually think it's worth improving the situation here. If the It's true that existing tools may need updates if we change e.g. |
I agree, but there's an existing issue for discussing this: #100129 |
Bug report
Bug description:
CPython versions tested on:
3.12, 3.13
Operating systems tested on:
Linux
The text was updated successfully, but these errors were encountered: