python-betterproto
python-betterproto copied to clipboard
Compiled comments are stripped of newlines
Compare line breaks in comments 👇
// `Any` contains an arbitrary serialized protocol buffer message along with a
// URL that describes the type of the serialized message.
//
// Protobuf library provides support to pack/unpack Any values in the form
// of utility functions or additional generated methods of the Any type.
message Any {
}
@dataclass
class Any(betterproto.Message):
"""
`Any` contains an arbitrary serialized protocol buffer message along with a
URL that describes the type of the serialized message. Protobuf library
provides support to pack/unpack Any values in the form of utility functions
or additional generated methods of the Any type.
"""
@boukeversteegh I saw you are involve in the some issues related to the support of Any type.
Do you know if there's some news for supporting Any in the coming releases ?
For whoever picks this up, in issue #310 I suggested also updating the code examples in the docstring to be betterproto style code instead of C++, Java, and google-Python.
Another example:
syntax = "proto3";
message MyMessage {
// JSON data in the following format:
// {
// "name": "Foo",
// "age": 0,
// "job": {
// "area": "Bar",
// "salary": 0
// }
// }
string json = 1;
}
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: mymessage.proto
# plugin: python-betterproto
from dataclasses import dataclass
import betterproto
@dataclass(eq=False, repr=False)
class MyMessage(betterproto.Message):
json: str = betterproto.string_field(1)
"""
JSON data in the following format: { "name": "Foo", "age": 0,
"job": { "area": "Bar", "salary": 0 } }
"""
It's great that it detects the comments and turns them into docstrings, but it breaks the formatting. I'd like to get the following result:
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: mymessage.proto
# plugin: python-betterproto
from dataclasses import dataclass
import betterproto
@dataclass(eq=False, repr=False)
class MyMessage(betterproto.Message):
json: str = betterproto.string_field(1)
"""
JSON data in the following format:
{
"name": "Foo",
"age": 0,
"job": {
"area": "Bar",
"salary": 0
}
}
"""
Adding that there are examples of this already in the existing tests:
https://github.com/danielgtaylor/python-betterproto/blob/5666393f9d10e13609d8eeac8d1ab3815dce5fd6/tests/inputs/example/example.proto#L834-L880
https://github.com/danielgtaylor/python-betterproto/blob/5666393f9d10e13609d8eeac8d1ab3815dce5fd6/src/betterproto/lib/google/protobuf/init.py#L1234-L1257
This was fixed in #532
Any reason the tests pass if the generated example in master does not appear to have this fix?
I'm not entirely sure we test it but also testing stability of comments seems very fragile.