Commit eb4fd97
Fix crash involving explicit reexport, import cycle, wildcard (python#11632)
Fixes python#8481
Fixes python#9941
Fixes python#11025
Fixes python#11038
This is the unresolved crash that's been reported the most times, e.g., it's as easy
to repro as `mypy --no-implicit-reexport -c 'import pytorch_lightning'` (or even
`import torch`, with the right PyTorch version). I know of multiple popular Python
packages that have made changes just to work around this crash. I would love to
see this released, potentially along with python#11630.
Thanks to @rraval for making a minimal repro!
The fix ended up being a one-liner, but it took me a bit to track down :-)
Since things worked with implicit reexport, I differentially patched in explicit reexport
logic to narrow things down. This let me observe that if I hardcoded pkg.a.B to get
reexported, we hit this branch, which clobbers the PlaceholderNode for pkg.c.B,
which fixes things:
https://github.com/python/mypy/blob/f79e7afec2c863c34d7a9b41ebb732dc26128fff/mypy/semanal.py#L2028
Which is a little weird — we shouldn't have a PlaceholderNode for pkg.c.B at all. But
with a breakpoint in that branch, it was easy to notice that with `--no-implicit-reexport`
pkg.a.B was first created with `module_public=True` (resulting in creation of a
PlaceholderNode in pkg.c.B) and only on a later pass acquired `module_public=False`.
So tracking down where pkg.a.B symbol was first created with `module_public=True`
led me to this "obvious" bug.1 parent 3f6a197 commit eb4fd97
2 files changed
+28
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1933 | 1933 | | |
1934 | 1934 | | |
1935 | 1935 | | |
1936 | | - | |
| 1936 | + | |
| 1937 | + | |
| 1938 | + | |
1937 | 1939 | | |
1938 | 1940 | | |
1939 | 1941 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5585 | 5585 | | |
5586 | 5586 | | |
5587 | 5587 | | |
| 5588 | + | |
| 5589 | + | |
| 5590 | + | |
| 5591 | + | |
| 5592 | + | |
| 5593 | + | |
| 5594 | + | |
| 5595 | + | |
| 5596 | + | |
| 5597 | + | |
| 5598 | + | |
| 5599 | + | |
| 5600 | + | |
| 5601 | + | |
| 5602 | + | |
| 5603 | + | |
| 5604 | + | |
| 5605 | + | |
| 5606 | + | |
| 5607 | + | |
| 5608 | + | |
| 5609 | + | |
| 5610 | + | |
| 5611 | + | |
| 5612 | + | |
0 commit comments