protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Python: Add type hints and py.typed

Open gitpushdashf opened this issue 3 years ago • 7 comments
trafficstars

It'd be great if the Python protobuf package included a py.typed file (indicating to mypy and such that the package has type hints), and adding type hints to the codebase.

At the moment, I'm using the types-protobuf package but would prefer to have the types integrated.

I realize this is a large undertaking. Just opening this issue up to refer back to it.

gitpushdashf avatar May 05 '22 15:05 gitpushdashf

What types-protobuf package do you mean?

Have you tried to use protoc generate python stubs (.pyi) with --pyi_out

anandolee avatar May 06 '22 03:05 anandolee

Thanks for getting back to me! I'm talking about stubs for the protobuf package itself, not generated stubs.

There's no type hints here or py.typed file: https://github.com/protocolbuffers/protobuf/tree/main/python/google/protobuf

gitpushdashf avatar May 06 '22 16:05 gitpushdashf

Sounds reasonable. We do have .pyi file in google internal for message.py, text_format.py and well_known_types.py. Will see if we can release them into opensource too

anandolee avatar May 07 '22 04:05 anandolee

Great, thank you!

gitpushdashf avatar May 09 '22 16:05 gitpushdashf

I have the same suggestion as @gitpushdashf but let me rephrase it. You have generic Protos, that you are compiling and including in the protobuf package like https://github.com/protocolbuffers/protobuf/blob/main/src/google/protobuf/wrappers.proto and other protos defined in that folder. Could you include stubs for them to the package? Since that code is already generated, the only thing left is adding *.pyi files to the package.

valerii-vorobiov avatar May 11 '22 10:05 valerii-vorobiov

Sounds reasonable. We do have .pyi file in google internal for message.py, text_format.py and well_known_types.py. Will see if we can release them into opensource too

Hello, would you please help me ? Have yet public into opensource now? I have found that there is no type hints for internal apis when use functions of protobuf lib.

huiyan-dev avatar Nov 18 '23 02:11 huiyan-dev

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 inactive because the last activity was over 90 days ago.

github-actions[bot] avatar Feb 16 '24 10:02 github-actions[bot]

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 reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

github-actions[bot] avatar Mar 02 '24 10:03 github-actions[bot]