Calling enums Name or Value breaks MyPy typecheck
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
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
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.
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.