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
recreate_module: set __spec__ to the new module #7773
Conversation
Codecov ReportBase: 89.75% // Head: 89.60% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #7773 +/- ##
==========================================
- Coverage 89.75% 89.60% -0.15%
==========================================
Files 138 128 -10
Lines 17007 15860 -1147
Branches 2515 2346 -169
==========================================
- Hits 15264 14212 -1052
+ Misses 1491 1421 -70
+ Partials 252 227 -25
Flags with carried forward coverage won't be shown. Click here to find out more.
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
The test failure looks unrelated. |
yes, can add some tests for the changes proposed? |
I can add something like follows, but I am not sure if it's worth it considering it's only used once: from importlib.util import find_spec
class test_celery_import:
def test_import_celery(self, monkeypatch):
import celery
monkeypatch.delitem(sys.modules, "celery", raising=False)
spec = find_spec("celery")
assert spec
assert celery.__spec__ == spec
assert find_spec("celery") == spec |
some test is better the no test, so lets add the test as well |
Thanks, I have added one. |
The recreated module has
__spec__
set toNone
, due to whichfind_spec
throwsValueError
.Reading PEP-451 and Python's docs for
__spec__
, it seems that__spec__
can beNone
in some cases but generally it should be set.Here's the issue that this tries to fix:
I noticed this when investigating failure in pylint/astroid, see PyCQA/pylint#7488 and PyCQA/astroid#1802.