Open AlexanderZender opened 2 years ago
You mean something like the following?
syntax = "proto3";
package hello;
// Greeting represents a message you can tell a user.
message Greeting {
string message = 1; // This is a comment.
}
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: example.proto
# plugin: python-betterproto
from dataclasses import dataclass
import betterproto
@dataclass
class Greeting(betterproto.Message):
"""Greeting represents a message you can tell a user."""
message: str = betterproto.string_field(1) # This is a comment.
Apparently, the following might actually also be valid, and could potentially be used in auto docs:
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: example.proto
# plugin: python-betterproto
from dataclasses import dataclass
import betterproto
@dataclass
class Greeting(betterproto.Message):
"""Greeting represents a message you can tell a user."""
message: str = betterproto.string_field(1)
"""This is a comment."""
I was under the impression that betterproto already did this now
I think it does only the class docstring ("""Greeting represents a message you can tell a user."""
), but ignores comments on the individual attributes (This is a comment.
).
Upon further testing, it seems like it does include some comments on attributes as well, but when they're written above the attribute, and not in front of them, like so:
syntax = "proto3";
package hello;
// Greeting represents a message you can tell a user.
message Greeting {
// This is a comment about `message`.
string message = 1;
}
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: example.proto
# plugin: python-betterproto
from dataclasses import dataclass
import betterproto
@dataclass
class Greeting(betterproto.Message):
"""Greeting represents a message you can tell a user."""
message: str = betterproto.string_field(1)
"""This is a comment about `message`."""
Given this, I'm now unsure of whether or not it'd be a good idea to include the comments written on the same line as the attribute. Maybe something like this could work:
syntax = "proto3";
package hello;
// Greeting represents a message you can tell a user.
message Greeting {
// This is a comment about `message`.
string message = 1; // And an inline comment.
}
# Generated by the protocol buffer compiler. DO NOT EDIT!
# sources: example.proto
# plugin: python-betterproto
from dataclasses import dataclass
import betterproto
@dataclass
class Greeting(betterproto.Message):
"""Greeting represents a message you can tell a user."""
message: str = betterproto.string_field(1) # And an inline comment.
"""This is a comment about `message`."""
This would keep the current behavior and also support inline comments.
Hi, is it possible to include comments describing services and their methods in Python files generated by betterproto?
Proto file example:
// Description of the service
service Test {
// Description of the method
rpc ExampleMethod(ExampleRequest) returns (ExampleResponse);
}
This is implemented now, it should be available in the next release
The google GRPC compiler copies the comments made in the proto files to their .py counter parts.
For code documentation it would be great if the betterproto compiler could also copy over the added comments from methods and messages.