Repository navigation
Commit 97766ec
authored
[mypyc] Fix segfault when importing package with module-level __getattr__ (#22205)
Fixes mypyc/mypyc#1198.
Importing a compiled package that defines a module-level `__getattr__`
could segfault:
```python
# pkg/__init__.py
def __getattr__(name: str) -> object:
raise AttributeError(name)
```
When initializing a module, mypyc checks whether `__file__`, `__path__`
and other module attributes are already set using `getattr`, and this
calls the module `__getattr__` if the attribute is not found. Since
module-level functions are available before the module body has been
executed, this calls compiled code before the module has been fully
initialized.
Now these attributes are looked up directly from the module dict, so
that `__getattr__` is not called.1 parent 457f913 commit 97766ec
2 files changed
Lines changed: 39 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1224 | 1224 | | |
1225 | 1225 | | |
1226 | 1226 | | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
| 1231 | + | |
| 1232 | + | |
| 1233 | + | |
| 1234 | + | |
| 1235 | + | |
| 1236 | + | |
| 1237 | + | |
| 1238 | + | |
1227 | 1239 | | |
1228 | 1240 | | |
1229 | 1241 | | |
1230 | 1242 | | |
1231 | 1243 | | |
1232 | 1244 | | |
1233 | 1245 | | |
1234 | | - | |
| 1246 | + | |
1235 | 1247 | | |
1236 | 1248 | | |
1237 | 1249 | | |
| |||
1271 | 1283 | | |
1272 | 1284 | | |
1273 | 1285 | | |
1274 | | - | |
| 1286 | + | |
1275 | 1287 | | |
1276 | 1288 | | |
1277 | 1289 | | |
| |||
1396 | 1408 | | |
1397 | 1409 | | |
1398 | 1410 | | |
1399 | | - | |
| 1411 | + | |
1400 | 1412 | | |
1401 | 1413 | | |
1402 | 1414 | | |
| |||
1405 | 1417 | | |
1406 | 1418 | | |
1407 | 1419 | | |
1408 | | - | |
| 1420 | + | |
1409 | 1421 | | |
1410 | 1422 | | |
1411 | 1423 | | |
| |||
1435 | 1447 | | |
1436 | 1448 | | |
1437 | 1449 | | |
1438 | | - | |
| 1450 | + | |
1439 | 1451 | | |
1440 | 1452 | | |
1441 | 1453 | | |
| |||
1449 | 1461 | | |
1450 | 1462 | | |
1451 | 1463 | | |
1452 | | - | |
| 1464 | + | |
1453 | 1465 | | |
1454 | 1466 | | |
1455 | 1467 | | |
| |||
1479 | 1491 | | |
1480 | 1492 | | |
1481 | 1493 | | |
1482 | | - | |
| 1494 | + | |
1483 | 1495 | | |
1484 | 1496 | | |
1485 | 1497 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4198 | 4198 | | |
4199 | 4199 | | |
4200 | 4200 | | |
| 4201 | + | |
| 4202 | + | |
| 4203 | + | |
| 4204 | + | |
| 4205 | + | |
| 4206 | + | |
| 4207 | + | |
| 4208 | + | |
| 4209 | + | |
| 4210 | + | |
| 4211 | + | |
| 4212 | + | |
| 4213 | + | |
| 4214 | + | |
| 4215 | + | |
| 4216 | + | |
| 4217 | + | |
| 4218 | + | |
| 4219 | + | |
| 4220 | + | |
0 commit comments