Skip to content

Conversation

@mikeshardmind
Copy link
Contributor

This fixes an assignablity issue in subclasses that was caused by using too strict an annotation for the purpose of __slots__ as a special case for mypy.

We can keep an annotation here for mypy if really needed, but it needs to work with subclass assignability.

ideally, long term all data model names are understood as part of the specification, but this needs to be permissive enough to allow subclasses to add members.

See error in pyright as a result of adding a special case for mypy: microsoft/pyright#11058

This fixes an assignablity issue in subclasses that was caused by using too strict an annotation for the purpose of `__slots__` as a special case for mypy.

We can keep an annotation here for mypy if really needed, but it needs to work with subclass assignability.

ideally, long term all data model names are understood as part of the specification, but this needs to be permissive enough to allow subclasses to add members.

See error in pyright as a result of adding a special case for mypy: microsoft/pyright#11058
@AlexWaygood
Copy link
Member

Thanks! It looks like there are a few other instances that we should probably fix similarly -- could you maybe do those too?

~/dev/typeshed (main)⚡ [1] % git grep '__slots__: tuple\[()\]'
stdlib/asyncio/protocols.pyi:    __slots__: tuple[()] = ()
stdlib/asyncio/protocols.pyi:    __slots__: tuple[()] = ()
stubs/protobuf/google/protobuf/internal/well_known_types.pyi:    __slots__: tuple[()] = ()
stubs/protobuf/google/protobuf/internal/well_known_types.pyi:    __slots__: tuple[()] = ()
stubs/protobuf/google/protobuf/message.pyi:    __slots__: tuple[()] = ()

@mikeshardmind
Copy link
Contributor Author

sure, is it better in this case to put them all in this PR, or will it work better for history if these are seperate?

@AlexWaygood
Copy link
Member

I think we added them all in one PR, so it probably makes sense to fix them all in one PR. I also don't mind if you'd rather split them up, though!

@github-actions

This comment has been minimized.

@mikeshardmind
Copy link
Contributor Author

mikeshardmind commented Nov 4, 2025

All in one seems simpler then. That was a much smarter grep than what I used, I just checked for the known comment, figuring it would have been replicated to explain anywhere that was used for that reason.

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

thanks!

@github-actions
Copy link
Contributor

github-actions bot commented Nov 4, 2025

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

@AlexWaygood AlexWaygood merged commit 29f78dd into python:main Nov 4, 2025
66 checks passed
@mikeshardmind mikeshardmind deleted the patch-1 branch November 4, 2025 22:20
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