Repository navigation
Commit 2b0aa85
committed
Import a lazy submodule that a package attribute shadows
_Py_module_getattro_impl consults lazy_pending_submodules only once ordinary
lookup has missed, so a `sub` bound by pkg/__init__.py answers the read that
was meant to trigger a pending `import pkg.sub`, and the submodule is never
imported. An eager `import pkg.sub` replaces that attribute with the
submodule, so the two modes disagree.
Bind the submodule on the package instead, at the two points where the eager
import would have: when the package finishes loading, and at registration
when it is already loaded. _imp._set_lazy_attributes() now does what its
name, and the comment on lazy_pending_submodules, already describe.
That needs to tell `import a.b`, whose last component must be a submodule,
from `from a import b` and `import a.b as x`, whose last component may be an
ordinary attribute. lazy_pending_submodules now records which of the two a
pending name came from, and IMPORT_FROM retracts the claim for the `as` form
before anything is resolved.
The repro in pythongh-151208 was fixed by pythongh-155194; this covers the shapes that
survived it -- a sibling or parent import rebinding the name, and a lazy
submodule registered after its package is loaded.1 parent 8542958 commit 2b0aa85
12 files changed
Lines changed: 166 additions & 13 deletions
File tree
- Include/internal
- Lib/test/test_lazy_import
- data
- submodule_name_shadowed
- Misc/NEWS.d/next/Core_and_Builtins
- Python
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
2209 | 2210 | | |
2210 | 2211 | | |
2211 | 2212 | | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
| 2217 | + | |
| 2218 | + | |
| 2219 | + | |
| 2220 | + | |
| 2221 | + | |
| 2222 | + | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
| 2234 | + | |
2212 | 2235 | | |
2213 | 2236 | | |
2214 | 2237 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
Whitespace-only changes.
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2690 | 2690 | | |
2691 | 2691 | | |
2692 | 2692 | | |
| 2693 | + | |
2693 | 2694 | | |
2694 | 2695 | | |
2695 | 2696 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
0 commit comments