-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
Three inconsistent module attributes #81700
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
Analysis In the next two sections showing the module attributes and corresponding spec attributes of imported modules and run modules, we notice the following rule (which is in accordance with this
However we also notice three exceptions to this rule, that I think are unintended inconsistencies that should be corrected:
The first exception was introduced recently (26 February 2018) by this Environment: CPython 3.7, MacOS 10.14. Imported modules Running the following code:: import module
print("MODULE")
print("SPEC")
if hasattr(module, "__spec__"):
if module.__spec__ is None:
print("__spec__:", repr(module.__spec__))
else:
for attr in ["name", "origin", "cached", "submodule_search_locations", "parent", "loader"]:
print(f"__spec__.{attr}:", repr(getattr(module.__spec__, attr)))
else:
print("__spec__: not set") where
prints the following module attributes and corresponding spec attributes of the imported
| MODULE
| MODULE
| MODULE
| MODULE
| MODULE Run modules Putting the following code:: import sys
print("MODULE")
print("SPEC")
if hasattr(sys.modules[__name__], "__spec__"):
if sys.modules[__name__].__spec__ is None:
print("__spec__:", repr(sys.modules[__name__].__spec__))
else:
for attr in ["name", "origin", "cached", "submodule_search_locations", "parent", "loader"]:
print(f"__spec__.{attr}:", repr(getattr(sys.modules[__name__].__spec__, attr)))
else:
print("__spec__: not set") in:
and running the code:
prints the following module attributes and corresponding spec attributes of the run
| $ python3 module.py
| $ python3 module/
| $ python3 module/ |
PEPs actually become historical documents once they are implemented, so could you please check what the official docs say in regards to this to see if there is an inconsistency in the semantics? |
@brett Cannon
Actually the inconsistency of the values of the 3 module attributes ( For
which is inconsistent: it should always be 'not set' when For
which is inconsistent: it should always be 'not set' when For
which is inconsistent: it should always be |
While some of these might be inconsistent (I haven't really looked at it thoroughly yet), I think it might be problematic to change them at this point, since there's no doubt code out there that depends on the current behavior. |
Related: #64019 |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: