Skip to content

Render docstrings and expose service descriptor#305

Open
anuraaga wants to merge 1 commit into
connectrpc:mainfrom
anuraaga:service-docs
Open

Render docstrings and expose service descriptor#305
anuraaga wants to merge 1 commit into
connectrpc:mainfrom
anuraaga:service-docs

Conversation

@anuraaga

Copy link
Copy Markdown
Collaborator

This renders docstrings for service and method very similar to how protobuf-py does for other types. It also adds a desc() classmethod for accessing the descriptor also following protobuf-py's model. I debated against a module-level constant since there isn't anything async or sync about the descriptor, but it felt cleanest going with this consistency instead.

Signed-off-by: Anuraag Agrawal <anuraaga@gmail.com>
@anuraaga
anuraaga requested a review from a team July 17, 2026 05:24
f.print(
"return next(s for s in ",
service.file,
".desc().services if s.type_name == '",

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I considered threading in the index within the descriptor we see here, but while it should be quite rare, it could be possible for the pb to change especially ordering of items without regenerating connect for some reason. Didn't seem worth avoiding this more flexible matching.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're maybe missing the /**/* in our own .gitattributes to properly mark these files as generated (think this approach in protobuf-py should work).



class ServerReflection(Protocol):
""""""

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe should skip completely empty docstrings?

@stefanvanburen stefanvanburen left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good, I think we ought to just skip empty docstrings though(?) (and would be nice to fix the .gitattributes as well)

Comment on lines +549 to +552
for line in text.splitlines():
# Comments in protobuf often start with a space, this
# leads to weird indentation in the generated docstring, so we remove it.
f.print(line.removeprefix(" "))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems reasonable to me as a first pass — I think both buf format and some of the other plugins have had to make tweaks over time to make this right for the ecosystem. Not too concerned with a little churn in the comments if we need to revisit (and not coming up with a better suggestion now).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants