-
Notifications
You must be signed in to change notification settings - Fork 15.6k
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
[Python] Protobuf python generated pb2 files are without typing files #16115
Comments
This should be fairly easy to do using https://pypi.org/project/mypy-protobuf/ I'd love to see protobuf provide their own generated stubs. In the mean time you can install https://pypi.org/project/types-protobuf/ |
@Avasam yes for mypy it works with mypy-protobuf, but not with pylint. We actually use both. |
Sounds like a pylint issue https://github.com/pylint-dev/pylint/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc+pyi+in%3Atitle Pylint didn't even support linting pyi files until last year: pylint-dev/astroid#2182 Specifically relevant issues: pylint-dev/pylint#6281 & pylint-dev/pylint#9185 |
@Avasam pylint supports pyi just fine and we are using them in our own proto files. But when using timestamp from protobuf package it does not work for that specific type. This is the main reason for this ticket. To also generate typing pyi files. Because then it works out of the box with latest pylint. For mypy yes it works with mypy-protobuf, but wouldn't it be better to just use python native typing option instead since it is already implemented and it works just bundled generated code is lacking them? |
We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment. This issue is labeled |
This issue is still pending. Python introduced pyi files with https://peps.python.org/pep-0561/ and it helps IDE, linters and other tools to correctly get type information from python files. Protobuf is still missing bundled pyi files for auto generated files (like timestamp) requiring third party plugins (like mypy-protobuf) instead of using recommended and official way. |
@matejsp Isn't this what you are looking for? I set
|
We do that already for our own generated python code from proto files. But I cannot do that for google.protobuf.timestamp_pb2 since timestamp_pb2 is bundled from this repostiory python whl. Basically this issue is about adding --pyi_out to the following code in this repo: |
I see, so you want the builtin types to have pyi files as well 😅 understood. |
Please generate with pyi files for python for builtin types.
Currently we have a lot of errors using those types with pylint and need to ignore checking:
What version of protobuf and what language are you using?
Version: 4.25.2 (from pypi)
Language: Python
What operating system (Linux, Windows, ...) and version?
MacOSX, Linux
What runtime / compiler are you using (e.g., python version or gcc version)
python 3.11.2
What did you do?
What did you expect to see
Protobuf should include pyi files and pass pylint validation when using timestampa type.
What did you see instead?
Anything else we should know about your project / environment
/
The text was updated successfully, but these errors were encountered: