aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/compiler
diff options
context:
space:
mode:
authorGravatar Mehrdad Afshari <mmx@google.com>2017-04-12 14:19:49 -0700
committerGravatar Mehrdad Afshari <mehrdada@users.noreply.github.com>2017-04-18 12:32:40 -0700
commit68f6a6732771e0265bb656d189de4b76d8268033 (patch)
treec05a5499c439a607dc42bfc5e8932286f2d3c8f3 /src/compiler
parent013eda440b1e203c06254a161e93156a5f761c3c (diff)
Always generate body for python code elements
Since #... class Service: class NextService: #... without a body or `pass` under `Service` is invalid Python, we ensure a `pass` statement is always emitted to make the generated code valid.
Diffstat (limited to 'src/compiler')
-rw-r--r--src/compiler/python_generator.cc8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/compiler/python_generator.cc b/src/compiler/python_generator.cc
index 2649c1688d..50ee54abff 100644
--- a/src/compiler/python_generator.cc
+++ b/src/compiler/python_generator.cc
@@ -101,6 +101,14 @@ PrivateGenerator::PrivateGenerator(const GeneratorConfiguration& config,
void PrivateGenerator::PrintAllComments(StringVector comments,
grpc_generator::Printer* out) {
if (comments.empty()) {
+ // Python requires code structures like class and def to have
+ // a body, even if it is just "pass" or a docstring. We need
+ // to ensure not to generate empty bodies. We could do something
+ // smarter and more sophisticated, but at the moment, if there is
+ // no docstring to print, we simply emit "pass" to ensure validity
+ // of the generated code.
+ out->Print("# missing associated documentation comment in .proto file\n");
+ out->Print("pass\n");
return;
}
out->Print("\"\"\"");