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
Unexpected exception with importlib #79972
Comments
Using Python 3.7.2 on macOS 10.14 I get an unexpected exception when calling "importlib.util.find_spec('py')" after importing "py". find_spec works as expected before I import 'py'. See the repl session below: Python 3.7.2 (v3.7.2:9a3ffc0492, Dec 24 2018, 02:44:43)
[Clang 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import importlib.util
>>> importlib.util.find_spec("py")
ModuleSpec(name='py', loader=<_frozen_importlib_external.SourceFileLoader object at 0x10a953fd0>, origin='/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/py/__init__.py', submodule_search_locations=['/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/py'])
>>> import py
>>> importlib.util.find_spec("py")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/util.py", line 111, in find_spec
raise ValueError('{}.__spec__ is not set'.format(name)) from None
ValueError: py.__spec__ is not set This is with py version 1.7.0 installed (pip install py) |
This might be a bug in "py", which uses a vendored version of apipkg that replaces sys.modules["py"] with a lazy loading object. That copy of apipkg does not copy __spec__ into the lazy loading object. If this is indeed consider to be a bug in py I'll file an issue with them. |
Yep, that's a bug in |
I expected as much. I've filed an issue with apipkg for this: pytest-dev/apipkg#13. My next challenge is to find a way to work around this issue in my code. BTW. Typing.io is a namespace added to sys.modules by the typing module that also does not have __spec__, and causes similar problems. I have an simple workaround for that on my side. |
FYI, I opened bpo-35806 for typing.io. |
bpo-35839 is follow-up enhancement request, proposing that we tweak the sys.modules handling in find_spec to ignore cache entries that don't have a __spec__ attribute set. |
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: