#32763·grpc

python: generator produces useless/empty files for proto files that do not define services

Author: jhumpCreated Mar 31, 2023Updated Sep 16, 2026
Labelskind/enhancementdisposition/help wantedlang/Pythonpriority/P2

The generator for python generates mostly empty (and totally useless) output files when processing a Proto source file that does not define any services.

First reported to Buf in our Slack. https://bufbuild.slack.com/archives/CRZ680FUH/p1679937428898619

The issues seems to be here: it gets to this point unconditionally and then calls context->Open, so it always produces a file, even if it will not actually generate any useful code for it.

Before it gets that far, probably around here, it should query file->service_count(): if the count is zero, it could just immediately return and generate nothing.