Repository navigation
Don't require __file__ when installing the lazy module - #2744
Open
Cherith1222 wants to merge 2 commits into
Open
Cherith1222 wants to merge 2 commits into
Cherith1222 wants to merge 2 commits into
Conversation
Frozen importers omit __file__ and __path__. Reading them while replacing the package module raised NameError. AI-assisted (Cursor).
auvipy
self-requested a review
October 10, 2026 18:38
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2744 +/- ##
=======================================
Coverage 85.11% 85.12%
=======================================
Files 80 80
Lines 11357 11362 +5
Branches 1362 1364 +2
=======================================
+ Hits 9667 9672 +5
Misses 1470 1470
Partials 220 220 ☔ View full report in Codecov by Harness. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1121.
Importing kombu raised
NameError: name '__file__' is not definedwhen the importer did not define__file__. Issue #1121 shows that failure while celery imports kombu, at the point where the package module is replaced.__path__is optional in the same way.kombu/__init__.pycopied both names unconditionally. They are copied only when the name is present in the module globals. An empty string and an explicitNoneare still present, so they are still copied. A normal import still has__file__and__path__. The temporary copy dict stays on the replaced module and is not a public attribute ofkombu. Lazy attributes such asConnectionstill load.t/unit/test_module.pycovers both names missing, only__path__, only__file__, both present, an empty string, explicitNone, and that loading this file leaves the real module object in place.No changelog entry was added. The section at the top of the changelog is the already released 5.7.0b1.
On this commit (
335cc60605d3a652d69cddf8ebcba70aeea8a05e), Windows, Python 3.13:pytest t/unit/test_module.pywas 8 passed, and the same run witht/unit/test_log.pywas 28 passed. flake8 7.3.0, mypy 2.3.1, and pydocstyle 6.3.0 reported no issues on the changed module. Integration tests, tox, and a real PyOxidizer build were not run.AI-assisted (Cursor).
Cherith reviewed this diff and confirmed it with the person who helped draft it.