python-betterproto icon indicating copy to clipboard operation
python-betterproto copied to clipboard

Compiled comments are stripped of newlines

Open boukeversteegh opened this issue 5 years ago • 2 comments

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 avatar Jun 01 '20 21:06 boukeversteegh

@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 ?

nhuray avatar Jul 18 '21 15:07 nhuray

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.

davidmankin avatar Apr 21 '22 18:04 davidmankin

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
        }
    }
    """

MicaelJarniac avatar May 11 '23 12:05 MicaelJarniac

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

mbrancato avatar Jan 12 '24 14:01 mbrancato

This was fixed in #532

Gobot1234 avatar Jan 12 '24 14:01 Gobot1234

Any reason the tests pass if the generated example in master does not appear to have this fix?

mbrancato avatar Jan 12 '24 16:01 mbrancato

I'm not entirely sure we test it but also testing stability of comments seems very fragile.

Gobot1234 avatar Jan 12 '24 16:01 Gobot1234