Commit aab59a0
Remove resolved names from sys.lazy_modules consistently
Names only left sys.lazy_modules through _imp._set_lazy_attributes(), which
the import machinery calls from _find_and_load_unlocked(). Two cases never
reached it, so their names were recorded and then kept forever:
- A lazy import of a module already in sys.modules. _find_and_load() returns
early, so nothing ever discards the name. Do not record it in the first
place.
- The "pkg.attr" entry for `lazy from pkg import attr`. The import machinery
only discards module names, and attr is often not a module. Discard it when
the lazy object is reified, where the name is already known and has been
resolved either way.
Submodules that are not yet loaded are still tracked: loading a package does
not load its submodules, so those imports can still fire. Names whose
reification failed also stay tracked, since the import can still happen.1 parent 1e8ff18 commit aab59a0
3 files changed
Lines changed: 143 additions & 7 deletions
File tree
- Lib/test/test_lazy_import
- Misc/NEWS.d/next/Core_and_Builtins
- Python
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
| 56 | + | |
| 57 | + | |
57 | 58 | | |
58 | 59 | | |
59 | 60 | | |
| |||
1275 | 1276 | | |
1276 | 1277 | | |
1277 | 1278 | | |
| 1279 | + | |
| 1280 | + | |
| 1281 | + | |
| 1282 | + | |
| 1283 | + | |
| 1284 | + | |
| 1285 | + | |
| 1286 | + | |
| 1287 | + | |
| 1288 | + | |
| 1289 | + | |
| 1290 | + | |
| 1291 | + | |
| 1292 | + | |
| 1293 | + | |
| 1294 | + | |
| 1295 | + | |
| 1296 | + | |
| 1297 | + | |
| 1298 | + | |
| 1299 | + | |
| 1300 | + | |
| 1301 | + | |
| 1302 | + | |
| 1303 | + | |
| 1304 | + | |
| 1305 | + | |
| 1306 | + | |
| 1307 | + | |
| 1308 | + | |
| 1309 | + | |
| 1310 | + | |
| 1311 | + | |
| 1312 | + | |
| 1313 | + | |
| 1314 | + | |
| 1315 | + | |
| 1316 | + | |
| 1317 | + | |
| 1318 | + | |
| 1319 | + | |
| 1320 | + | |
| 1321 | + | |
| 1322 | + | |
| 1323 | + | |
| 1324 | + | |
| 1325 | + | |
| 1326 | + | |
| 1327 | + | |
| 1328 | + | |
| 1329 | + | |
| 1330 | + | |
| 1331 | + | |
| 1332 | + | |
| 1333 | + | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
| 1340 | + | |
| 1341 | + | |
| 1342 | + | |
| 1343 | + | |
| 1344 | + | |
| 1345 | + | |
| 1346 | + | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
| 1363 | + | |
| 1364 | + | |
| 1365 | + | |
| 1366 | + | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
| 1375 | + | |
1278 | 1376 | | |
1279 | 1377 | | |
1280 | 1378 | | |
| |||
Lines changed: 3 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3917 | 3917 | | |
3918 | 3918 | | |
3919 | 3919 | | |
| 3920 | + | |
| 3921 | + | |
| 3922 | + | |
| 3923 | + | |
| 3924 | + | |
| 3925 | + | |
| 3926 | + | |
| 3927 | + | |
| 3928 | + | |
| 3929 | + | |
| 3930 | + | |
| 3931 | + | |
| 3932 | + | |
| 3933 | + | |
3920 | 3934 | | |
3921 | 3935 | | |
3922 | 3936 | | |
| |||
4100 | 4114 | | |
4101 | 4115 | | |
4102 | 4116 | | |
| 4117 | + | |
| 4118 | + | |
| 4119 | + | |
| 4120 | + | |
4103 | 4121 | | |
4104 | 4122 | | |
4105 | 4123 | | |
| |||
4358 | 4376 | | |
4359 | 4377 | | |
4360 | 4378 | | |
| 4379 | + | |
| 4380 | + | |
| 4381 | + | |
| 4382 | + | |
| 4383 | + | |
| 4384 | + | |
| 4385 | + | |
| 4386 | + | |
| 4387 | + | |
| 4388 | + | |
| 4389 | + | |
| 4390 | + | |
| 4391 | + | |
| 4392 | + | |
| 4393 | + | |
| 4394 | + | |
| 4395 | + | |
| 4396 | + | |
| 4397 | + | |
| 4398 | + | |
| 4399 | + | |
4361 | 4400 | | |
4362 | 4401 | | |
4363 | 4402 | | |
| |||
4451 | 4490 | | |
4452 | 4491 | | |
4453 | 4492 | | |
4454 | | - | |
4455 | | - | |
4456 | | - | |
| 4493 | + | |
4457 | 4494 | | |
4458 | 4495 | | |
4459 | 4496 | | |
| |||
4627 | 4664 | | |
4628 | 4665 | | |
4629 | 4666 | | |
4630 | | - | |
4631 | | - | |
4632 | | - | |
| 4667 | + | |
4633 | 4668 | | |
4634 | 4669 | | |
4635 | 4670 | | |
| |||
0 commit comments