protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

pyi plugin can generate syntactically invalid python

Open idletea opened this issue 11 months ago • 0 comments

None is a keyword, so it's invalid to attempt to use it as a name in a pyi file.

I would expect that the plugin wouldn't produce invalid python, even if that means it needs to emit a warning and not emit a given file.

What version of protobuf and what language are you using?

$ buf --version
1.50.0
$ cat buf.gen.yaml
version: v1
plugins:
  - plugin: buf.build/protocolbuffers/pyi:v30.1
    out: .

To reproduce

buf.gen.yaml

version: v1
plugins:
  - plugin: buf.build/protocolbuffers/pyi:v30.1
    out: .

foo.proto

syntax = "proto3";
package foo.v1;

message None {}

generated foo_pb2.pyi

from google.protobuf import descriptor as _descriptor
from google.protobuf import message as _message
from typing import ClassVar as _ClassVar

DESCRIPTOR: _descriptor.FileDescriptor

class None(_message.Message):
    __slots__ = ()
    def __init__(self) -> None: ...

What did you expect to see

Probably an error or at least warning indicating the name can't be used, and no .pyi file emitted.

What did you see instead?

$ python foo_pb2.pyi 
  File ".../foo_pb2.pyi", line 7
    class None(_message.Message):
          ^
SyntaxError: invalid syntax

idletea avatar Mar 27 '25 20:03 idletea