Skip to content

Format field comments as real docstrings #303

Closed
@michaelosthege

Description

@michaelosthege

This line https://github.com/danielgtaylor/python-betterproto/blob/master/src/betterproto/templates/template.py.j2#L49 formats the comments on class attributes like this.

With the example from the readme:

// This is the class docstring
message EchoRequest {
    string value = 1;
    // This is a field docstring
    uint32 extra_times = 2;
}

It generates this Python code:

@dataclass
class EchoRequest(betterproto.Message):
    """This is the class docstring"""

    value: str = betterproto.string_field(1)
    # This is a field docstring
    extra_times: int = betterproto.uint32_field(2)

But a slightly different formatting would make it a docstring recognized by IDEs:

class EchoRequest(betterproto.Message):
    """This is the class docstring"""

    value: str = betterproto.string_field(1)
    extra_times: int = betterproto.uint32_field(2)
    """This is a field docstring"""

image

Would you mind changing the formatting here? Or are there specific reasons why it produces the current output format?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions