-
Notifications
You must be signed in to change notification settings - Fork 80
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
Provide TypedDict types for json mapping of protobuf #131
Comments
Hi - looks like it is in typeshed https://github.com/python/typeshed/blob/master/third_party/2and3/google/protobuf/json_format.pyi Is there anything more specific you'd like to have in the autogenerated pyi files? |
based on my readthrough, the typing in typeshed covers the json_format. It's not clear to me what autogenerated |
Hi, |
What annotation are you looking for? Can you provide some example code which is under-annotated today? It looks like these json_mapping methods are annotated in typeshed. Is there anything more specific you'd like to have in the autogenerated pyi files? https://github.com/python/typeshed/blob/master/third_party/2and3/google/protobuf/json_format.pyi |
I presenting an example for both proto2 and proto3 implementations. For proto 2 message Hello {
required string name = 1;
required google.protobuf.Timestamp timestamp = 2;
}
message Sample {
optional string string = 1;
optional int64 large_int = 2;
optional Hello hello = 3;
required int32 small_int = 4;
repeated int32 numbers = 5;
} I want a auto generated typed classes be class Hello___JSON_PRESERVING(typing.TypedDict):
name: str
timestamp: str
class Sample___JSON_PRESERVING(typing.TypedDict):
string: typing.Optional[str]
large_int: typing.Optional[str]
hello: typing.Optional[Hello___JSON_PRESERVING]
small_int: int
numbers: typing.Optional[typing.List[int]]
class Hello___JSON(typing.TypedDict):
name: str
timestamp: str
class Sample___JSON(typing.TypedDict):
string: typing.Optional[str]
largeInt: typing.Optional[str]
hello: typing.Optional[Hello___JSON]
smallInt: int
numbers: typing.Optional[typing.List[int]] For proto 3 message Hello {
string name = 1;
google.protobuf.Timestamp timestamp = 2;
}
message Sample {
string string = 1;
int64 large_int = 2;
Hello hello = 3;
int32 small_int = 4;
int32 numbers = 5;
} I want a auto generated typed classes be class Hello___JSON_PRESERVING(typing.TypedDict):
name: typing.Optional[str]
timestamp: typing.Optional[str]
class Sample___JSON_PRESERVING(typing.TypedDict):
string: typing.Optional[str]
large_int: typing.Optional[str]
hello: typing.Optional[Hello___JSON_PRESERVING]
small_int: typing.Optional[int]
numbers: typing.Optional[typing.List[int]]
class Hello___JSON(typing.TypedDict):
name: typing.Optional[str]
timestamp: typing.Optional[str]
class Sample___JSON(typing.TypedDict):
string: typing.Optional[str]
largeInt: typing.Optional[str]
hello: typing.Optional[Hello___JSON]
smallInt: typing.Optional[int]
numbers: typing.Optional[typing.List[int]] |
Yep - this seems reasonable. I would be amenable to autogenerating these. They could be generated under the namespace of the original message - making importing easier - as For example
|
Hi,
It would be great if json_format definitions are also created while compiling the proto file.
Thanks,
Dilip Vamsi.
The text was updated successfully, but these errors were encountered: