Skip to content

--pyi_out does not annotate __slots__ #11402

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
remko opened this issue Dec 23, 2022 · 3 comments
Closed

--pyi_out does not annotate __slots__ #11402

remko opened this issue Dec 23, 2022 · 3 comments

Comments

@remko
Copy link

remko commented Dec 23, 2022

What version of protobuf and what language are you using?

Language: Python
protobuf 4.21.12
grpcio 1.51.1, grpcio-tools 1.51.1,
Mypy 0.991

What operating system (Linux, Windows, ...) and version?

macOS Ventura

What runtime / compiler are you using (e.g., python version or gcc version)

Python 3.9.16

What did you do?

Run python3 -m grpc_tools.protoc -pyi_out=...

What did you expect to see

A .pyi that validates Mypy type checks.

What did you see instead?

A .pyi that has the following error:

error: Need type annotation for "__slots__"

It seems __slots__ is the only untyped field in the .pyi.

@remko remko added the untriaged auto added to all issues by default when created. label Dec 23, 2022
@deannagarcia
Copy link
Member

I think this is a bug in Mypy (although the bug suggests the issue has been fixed).

@aiven-anton
Copy link

@deannagarcia Changing to using a tuple for __slots__ makes this error go away, which seems reasonable because tuples are immutable. Would you accept a PR that changes all generated __slots__ to use tuples for the pyi generator?

tmccombs added a commit to tmccombs/stormlock that referenced this issue Aug 26, 2023
@smheidrich
Copy link

smheidrich commented Nov 23, 2023

I was going to ask to reopen because this is still broken, with protoc outputting lists instead of tuples as mentioned by @aiven-anton. But actually, Python's docs on __slots__ do say

[...] a string, iterable, or sequence of strings [...]

So protoc is not doing anything wrong, lists should be fine and this is just another Mypy bug: python/mypy#10870

Maybe those affected can upvote there?

@googleberg googleberg removed the untriaged auto added to all issues by default when created. label Feb 17, 2024
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

No branches or pull requests

5 participants