- Update the autogenerated
.pyi
file header to citemypy-protobuf
- Reorganize mypy-protobuf testsuite files to more closely match autogeneration into a
generated
directory
- Inherit FromString from superclass Message - rather than re-generating here. Fixes bug
in python2 usage
google/protobuf/type_pb2.pyi:92: error: Argument 1 of "FromString" is incompatible with supertype "Message"; supertype defines the argument type as "ByteString" [override]
- Update tested/required mypy version to 0.780 (picks up new typeshed annotations). Includes improved typing/error messages on Message.
Before (mypy < 0.780):
test_negative/negative.py:26: error: Argument 1 to "CopyFrom" of "Message" has incompatible type "str"; expected "Message"
After (mypy >= 0.780:
test_negative/negative.py:26: error: Argument 1 to "CopyFrom" of "Message" has incompatible type "str"; expected "Simple1"
- Update generated EnumTypeWrapper to be instances of EnumTypeWrapper - for more consistency
with generated python code. Most caller code should not require mypy type changes. Egh
ProtoEnum.Value('first')
should work either way.
Generated Before (in 1.21)
class ProtoEnum(object):
@classmethod
def Value(cls, name: str) -> ProtoEnumValue
Generated After (in 1.22)
ProtoEnum: _ProtoEnum
class _ProtoEnum(google.protobuf.EnumTypeWrapper):
def Value(self, name: str) -> ProtoEnumValue
- Remove autogenerated EnumTypeWrapper methods that are redundant to the typeshed parent class. Added testing for these.
- Support for module descriptor.
- Update mangling from
global__
tomessage__
- Fix bug in message typing for nested enums. Split EnumValue from EnumTypeWrapper. Enforces that constructing an enum value must happen via a NewType wrapper to the int.
Example:
enum ProtoEnum {
FIRST = 1;
SECOND = 2;
}
mesage ProtoMsg {
ProtoEnum enum = 1;
}
Generated Before (in 1.20):
class ProtoEnum(object):
@classmethod
def Value(cls, name: str) -> ProtoEnum
class ProtoMsg(Message):
def __init__(self, enum: ProtoEnum) -> None
Generated After (in 1.21):
ProtoEnumValue = NewType('ProtoEnumValue', int)
class ProtoEnum(object):
@classmethod
def Value(cls, name: str) -> ProtoEnumValue
class ProtoMsg(Message):
def __init__(self, enum: ProtoEnumValue) -> None
Migration Guide (with example calling code)
Before (with 1.20)
from msg_pb2 import ProtoEnum, ProtoMsg
def make_proto_msg(enum: ProtoEnum) -> ProtoMsg:
return ProtoMsg(enum)
make_proto_msg(ProtoMsg.FIRST)
After (with 1.21)
from msg_pb2 import ProtoEnum, ProtoMsg
def make_proto_msg(enum: 'msg_pb2.ProtoEnumValue') -> ProtoMsg:
return ProtoMsg(enum)
make_proto_msg(ProtoMsg.FIRST)
- Use inline-style rather than comment-style typing in the pyi file
- Remove MergeFrom/CopyFrom from generated code as it is in the Message superclass
- Black code formatting
- Fix message/field name aliasing when field name matches a message/enum name
- Allow omitting required proto2 fields from constructor parameters
- Support and testing for python 3.8
- Support for python-protobuf to 3.11.3
- Use
entry_points:console_scripts
to support long paths to the python interpreter
- Update to newer mypy version - including minor changes to typeshed
- Absolute path to necessary python
- Add forward reference string literal support for enums
- Alias builtin types to avoid collision with field name
- Add
class
to set of python keywords
- Add
Message.DESCRIPTOR