GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||
GeezerVison is showing github.com — gh-158140: Resolve lazily imported sibling submodules independently by pablogsal · Pull Request #158521 · python/cpython Conversation
|
|
Sorry fucked up the squash give me sec |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
56babbc to
4e83bfa
Compare
|
Is this ready now @pablogsal? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Here's a somewhat surprising change in behaviour: given these two modules: A.py: B.py: Before this PR the use of With this PR, it reports the lazy import in B.py: Swapping the order of the lazy imports used to not have an effect on the traceback, but now it does: the last lazy import wins. I'm not sure if that's fixable, but I think if we need a single location the first lazy import would be a better winner. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Okay I think I see why we can't do that, either. I think this is fixable later (perhaps by merging lazy objects, storing all the locations and selecting an appropriate one when printing the traceback). Still, it's a little annoying that this used to work as users would expect. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I think there's a similar issue with modules defining |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
All things considered, LGTM. I think the semantic changes are acceptable for 3.15 and we can see if we can improve the error reporting later.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
🤖 New build scheduled with the buildbot fleet by @hugovk for commit 4e83bfa 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F158521%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
I think we can fix the A/B case by keeping the declarations keyed by the importing module’s I tried this locally. It’s about 70 lines of C. There’s still ambiguity if two namespaces share the same name, or the same filename for anonymous What do you think, @Yhg1s? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Yes, I was thinking something similar, but I don't think we should try to fix this for 3.15.0. We can pre-emptively file a bug and fix it later. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Only the root is now resolved.
|
I merged in the main branch with #157714. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Co-authored-by: T. Wouters <[email protected]> Co-authored-by: Petr Viktorin <[email protected]>
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks @pablogsal for the PR, and @Yhg1s for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-158613 is a backport of this pull request to the 3.15 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ently (GH-158521) (#158613) Co-authored-by: Pablo Galindo Salgado <[email protected]> Co-authored-by: Petr Viktorin <[email protected]> Co-authored-by: T. Wouters <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
…dependently (pythonGH-158521) (python#158613) Co-authored-by: Pablo Galindo Salgado <[email protected]> Co-authored-by: Petr Viktorin <[email protected]> Co-authored-by: T. Wouters <[email protected]> Co-authored-by: Hugo van Kemenade <[email protected]>
A pending child in `lazy_pending_submodules` is keyed only by `(parent, child)`, so a later declaration of the same name by another module replaces the earlier one. Resolving the child then copies the location out of the surviving declaration, so the chained `ImportError` points into the file of a module that merely declared the name. Key the declarations by the declaring module, and select one from the frame's globals at access time, so the child resolves with the declaration in scope where the access is written. A declaration made by another module still names the same child and imports the same thing, so it is still used when there is nothing in scope; its location is then not reported as a frame of the accessing module's traceback. The selection also decides which `__import__` runs, since `_PyLazyImport_LoadChild()` takes `lz_builtins` from the declaration it is given. An access that has a declaration of its own in scope now uses that module's hook instead of the last-registered one's — the case Yhg1s described in the pythongh-158521 review. An access with no declaration in scope is unchanged.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Accessing one lazily imported submodule (lazy import pkg.a) also imports a later imported pkg.b
There was an error while loading. Please reload this page.