Repository navigation
Commit 00da645
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 fcf0411 commit 00da645
9 files changed
Lines changed: 196 additions & 111 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 | | |
2212 | | - | |
2213 | | - | |
2214 | | - | |
2215 | | - | |
2216 | | - | |
2217 | | - | |
2218 | | - | |
| 2213 | + | |
| 2214 | + | |
| 2215 | + | |
| 2216 | + | |
2219 | 2217 | | |
2220 | | - | |
2221 | | - | |
2222 | | - | |
| 2218 | + | |
| 2219 | + | |
2223 | 2220 | | |
2224 | 2221 | | |
2225 | 2222 | | |
2226 | | - | |
2227 | | - | |
2228 | | - | |
2229 | | - | |
2230 | | - | |
2231 | | - | |
2232 | | - | |
| 2223 | + | |
| 2224 | + | |
| 2225 | + | |
| 2226 | + | |
| 2227 | + | |
| 2228 | + | |
| 2229 | + | |
| 2230 | + | |
| 2231 | + | |
| 2232 | + | |
| 2233 | + | |
2233 | 2234 | | |
2234 | 2235 | | |
2235 | 2236 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
This file was deleted.
Whitespace-only changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
2 | | - | |
3 | | - | |
4 | | - | |
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3360 | 3360 | | |
3361 | 3361 | | |
3362 | 3362 | | |
| 3363 | + | |
| 3364 | + | |
| 3365 | + | |
| 3366 | + | |
3363 | 3367 | | |
3364 | 3368 | | |
3365 | 3369 | | |
| |||
3374 | 3378 | | |
3375 | 3379 | | |
3376 | 3380 | | |
| 3381 | + | |
| 3382 | + | |
| 3383 | + | |
| 3384 | + | |
| 3385 | + | |
| 3386 | + | |
| 3387 | + | |
| 3388 | + | |
| 3389 | + | |
| 3390 | + | |
3377 | 3391 | | |
3378 | 3392 | | |
3379 | 3393 | | |
| |||
0 commit comments