Commit b69309b
authored
Prevent synthetic intersections from leaking to module public interfaces (#20459)
Fixes #20457.
---
In addition, 642cf64 fixes a bug which can be triggered in stubtest.
Reproducer:
```python
# mod.pyi
class A: ...
class B: ...
class AB(A, B): ...
a: A
if isinstance(a, B): ...
```
```python
# mod.py
class A: pass
class B: pass
class AB(A, B): pass
a = A()
```
```shell
$ stubtest mod
error: mod.<subclass of "mod.A" and "mod.B"> is not present at runtime
Stub: in file mod.pyi
<TypeInfo mod.<subclass of "mod.A" and "mod.B">>
Runtime:
MISSING
```
Admittedly, nobody should be writing `isinstance()` in a stub, but it
doesn't seem to be illegal to do so, and in any case auto-generated
stubs may forget to strip such constructs and surface weird error
messages like the one above.
I tried adding a test to `teststubtest.py`, but it fails because there
doesn't seem to be a way to add fixtures to test cases there, which is
needed to invoke `isinstance()`. The test is
```python
@collect_cases
def test_generated_intersection_non_public(self) -> Iterator[Case]:
yield Case(
stub="""
class A: ...
class B: ...
class AB(A, B): ...
a: A
if isinstance(a, B): ...
""",
runtime="""
class A: pass
class B: pass
class AB(A, B): pass
a: A
""",
error=None,
)
```1 parent 72cff30 commit b69309b
2 files changed
+20
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5968 | 5968 | | |
5969 | 5969 | | |
5970 | 5970 | | |
5971 | | - | |
| 5971 | + | |
5972 | 5972 | | |
5973 | 5973 | | |
5974 | 5974 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
593 | 593 | | |
594 | 594 | | |
595 | 595 | | |
| 596 | + | |
| 597 | + | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
| 605 | + | |
| 606 | + | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
| 612 | + | |
| 613 | + | |
| 614 | + | |
596 | 615 | | |
597 | 616 | | |
598 | 617 | | |
| |||
0 commit comments