protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Calling enums Name or Value breaks MyPy typecheck

Open arthur-proglove opened this issue 3 years ago • 1 comments

What version of protobuf and what language are you using? Version: 4.21.2 Language: Python

What operating system (Linux, Windows, ...) and version? ArchLinux

What runtime / compiler are you using (e.g., python version or gcc version) Python 3.7

What did you do?

  • Create a simple Protobuf enum
enum Foo {
  FOO_ZERO = 0;
  FOO_ONE = 1;
  FOO_TWO = 2;
}
  • Generate the the Python code
protoc --python_out=. --pyi_out=. foo.proto
  • Use the generated code
from foo_pb2 import Foo

print(Foo.Name(0))
  • Verify the code with MyPy

What did you expect to see

MyPy should pass without errors

What did you see instead?

MyPy complains that the type does not have the Name attribute

 error: "Type[Foo]" has no attribute "Name"

Anything else we should know about your project / environment

arthur-proglove avatar Jul 11 '22 12:07 arthur-proglove

mypy is reporting errors on the generated stubs. Those may have to be addressed first.

The stubs generated for enums use a metaclass not deriving from type, which causes an error.

class MyEnum(int, metaclass=_enum_type_wrapper.EnumTypeWrapper):
enum_pb2.pyi:154: error: Metaclasses not inheriting from "type" are not supported

ajasmin avatar Jul 27 '22 17:07 ajasmin

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please add a comment.

This issue is labeled inactive because the last activity was over 90 days ago.

github-actions[bot] avatar Jan 14 '24 10:01 github-actions[bot]

We triage inactive PRs and issues in order to make it easier to find active work. If this issue should remain active or becomes active again, please reopen it.

This issue was closed and archived because there has been no new activity in the 14 days since the inactive label was added.

github-actions[bot] avatar Jan 28 '24 10:01 github-actions[bot]