Skip to content

stubtest: flag redundant @disjoint_base decorators - #19715

Merged
JelleZijlstra merged 4 commits into
python:masterfrom
JelleZijlstra:redundant-disjoint
Aug 22, 2025
Merged

JelleZijlstra merged 4 commits into
python:masterfrom
JelleZijlstra:redundant-disjoint

Conversation

@JelleZijlstra

Copy link
Copy Markdown
Member

No description provided.

@AlexWaygood AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

looks good!

Comment thread mypy/stubtest.py
Comment on lines +543 to +559
elif stub.is_final:
yield Error(
object_path,
"is marked as @disjoint_base, but also marked as @final; remove @disjoint_base",
stub,
runtime,
stub_desc=repr(stub),
)
elif stub.is_enum and stub.enum_members:
yield Error(
object_path,
"is marked as @disjoint_base, but is an enum with members, which is implicitly final; "
"remove @disjoint_base",
stub,
runtime,
stub_desc=repr(stub),
)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

these feel like linter issues more than correctness issues (so sort-of outside of stubtest's normal purview?), but it's obviously very easy to check for them here, so I think it makes sense

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah we could also add these checks to flake8-pyi/ruff/whatever.

Comment thread mypy/test/teststubtest.py
Comment on lines -1410 to +1411
from typing_extensions import disjoint_base
if sys.version_info >= (3, 12):
class BytesEnum(bytes, enum.Enum):
a = b'foo'
else:
@disjoint_base
class BytesEnum(bytes, enum.Enum):
a = b'foo'
class BytesEnum(bytes, enum.Enum):
a = b'foo'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

one way to keep the test as it was before would be to just have it be an "abstract enum" that doesn't have any members

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I complicated this test in a previous PR for disjoint_base, so I don't feel bad about going back to the previous less complicated version.

Comment thread mypy/test/teststubtest.py Resolved
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@JelleZijlstra
JelleZijlstra merged commit fa7fa7f into python:master Aug 22, 2025
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.

2 participants