Skip to content

Conversation

@bzoracler
Copy link
Contributor

Fixes #20457.


In addition, 642cf64 fixes a bug which can be triggered in stubtest. Reproducer:

# mod.pyi
class A: ...
class B: ...
class AB(A, B): ...

a: A
if isinstance(a, B): ...
# mod.py
class A: pass
class B: pass
class AB(A, B): pass

a = A()
$ 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

    @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,
        )

@bzoracler bzoracler changed the title Fix 20457 Prevent synthetic intersections from leaking to module public interfaces Dec 22, 2025
@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@hauntsaninja hauntsaninja merged commit b69309b into python:master Dec 23, 2025
23 checks passed
@bzoracler bzoracler deleted the fix-20457 branch December 23, 2025 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Synthetic intersections are leaking in star imports

2 participants