diff options
author | robot-contrib <robot-contrib@yandex-team.com> | 2024-10-05 21:45:24 +0300 |
---|---|---|
committer | robot-contrib <robot-contrib@yandex-team.com> | 2024-10-05 21:59:24 +0300 |
commit | c3797467c201a8de261c9da5475b2386197cb4b0 (patch) | |
tree | e61929f737299abecd85f79501b1064630863be6 | |
parent | bb4b8d018c07ae166175cf29e5a3594ff942c7ce (diff) | |
download | ydb-c3797467c201a8de261c9da5475b2386197cb4b0.tar.gz |
Update contrib/python/mypy-protobuf to 3.6.0
commit_hash:755aa23eabf95904d16b474154b8df2a5044e78b
-rw-r--r-- | contrib/python/mypy-protobuf/.dist-info/METADATA | 6 | ||||
-rw-r--r-- | contrib/python/mypy-protobuf/README.md | 6 | ||||
-rw-r--r-- | contrib/python/mypy-protobuf/mypy_protobuf/extensions_pb2.py | 18 | ||||
-rw-r--r-- | contrib/python/mypy-protobuf/mypy_protobuf/main.py | 42 | ||||
-rw-r--r-- | contrib/python/mypy-protobuf/ya.make | 2 |
5 files changed, 35 insertions, 39 deletions
diff --git a/contrib/python/mypy-protobuf/.dist-info/METADATA b/contrib/python/mypy-protobuf/.dist-info/METADATA index 934bb64a10..eaa67dc8dc 100644 --- a/contrib/python/mypy-protobuf/.dist-info/METADATA +++ b/contrib/python/mypy-protobuf/.dist-info/METADATA @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: mypy-protobuf -Version: 3.5.0 +Version: 3.6.0 Summary: Generate mypy stub files from protobuf specs Home-page: https://github.com/nipunn1313/mypy-protobuf Download-URL: https://github.com/nipunn1313/mypy-protobuf/releases @@ -10,6 +10,6 @@ License: Apache License 2.0 Keywords: mypy proto dropbox Requires-Python: >=3.8 License-File: LICENSE -Requires-Dist: protobuf (>=4.23.4) -Requires-Dist: types-protobuf (>=4.23.0.2) +Requires-Dist: protobuf >=4.25.3 +Requires-Dist: types-protobuf >=4.24 diff --git a/contrib/python/mypy-protobuf/README.md b/contrib/python/mypy-protobuf/README.md index a1bfe29279..bccb090c9c 100644 --- a/contrib/python/mypy-protobuf/README.md +++ b/contrib/python/mypy-protobuf/README.md @@ -16,7 +16,7 @@ See [Changelog](CHANGELOG.md) for recent changes. Earlier releases might work, but aren't tested - [protoc >= 23.4](https://github.com/protocolbuffers/protobuf/releases) -- [python-protobuf >= 4.23.4](https://pypi.org/project/protobuf/) - matching protoc release +- [python-protobuf >= 4.25.3](https://pypi.org/project/protobuf/) - matching protoc release - [python >= 3.8](https://www.python.org/downloads/source/) - for running mypy-protobuf plugin. ## Requirements to run typecheckers on stubs generated by mypy-protobuf @@ -24,8 +24,8 @@ Earlier releases might work, but aren't tested Earlier releases might work, but aren't tested - [mypy >= v1.4.1](https://pypi.org/project/mypy) or [pyright >= 1.1.206](https://github.com/microsoft/pyright) -- [python-protobuf >= 4.23.4](https://pypi.org/project/protobuf/) - matching protoc release -- [types-protobuf >= 4.23.0.2](https://pypi.org/project/types-protobuf/) - for stubs from the google.protobuf library +- [python-protobuf >= 4.25.3](https://pypi.org/project/protobuf/) - matching protoc release +- [types-protobuf >= 4.24](https://pypi.org/project/types-protobuf/) - for stubs from the google.protobuf library ### To run typecheckers on code generated with grpc plugin - you'll additionally need diff --git a/contrib/python/mypy-protobuf/mypy_protobuf/extensions_pb2.py b/contrib/python/mypy-protobuf/mypy_protobuf/extensions_pb2.py index a638958a1b..5d48735c20 100644 --- a/contrib/python/mypy-protobuf/mypy_protobuf/extensions_pb2.py +++ b/contrib/python/mypy-protobuf/mypy_protobuf/extensions_pb2.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Generated by the protocol buffer compiler. DO NOT EDIT! # source: mypy_protobuf/extensions.proto +# Protobuf Python Version: 4.25.3 """Generated protocol buffer code.""" from google.protobuf import descriptor as _descriptor from google.protobuf import descriptor_pool as _descriptor_pool @@ -20,18 +21,13 @@ _globals = globals() _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, _globals) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'mypy_protobuf.extensions_pb2', _globals) if _descriptor._USE_C_DESCRIPTORS == False: - google_dot_protobuf_dot_descriptor__pb2.FieldOptions.RegisterExtension(options) - google_dot_protobuf_dot_descriptor__pb2.FieldOptions.RegisterExtension(casttype) - google_dot_protobuf_dot_descriptor__pb2.FieldOptions.RegisterExtension(keytype) - google_dot_protobuf_dot_descriptor__pb2.FieldOptions.RegisterExtension(valuetype) - DESCRIPTOR._options = None - casttype._options = None - casttype._serialized_options = b'\030\001' - keytype._options = None - keytype._serialized_options = b'\030\001' - valuetype._options = None - valuetype._serialized_options = b'\030\001' + _globals['casttype']._options = None + _globals['casttype']._serialized_options = b'\030\001' + _globals['keytype']._options = None + _globals['keytype']._serialized_options = b'\030\001' + _globals['valuetype']._options = None + _globals['valuetype']._serialized_options = b'\030\001' _globals['_FIELDOPTIONS']._serialized_start=83 _globals['_FIELDOPTIONS']._serialized_end=151 # @@protoc_insertion_point(module_scope) diff --git a/contrib/python/mypy-protobuf/mypy_protobuf/main.py b/contrib/python/mypy-protobuf/mypy_protobuf/main.py index f0b3dbc7e8..343b80b3af 100644 --- a/contrib/python/mypy-protobuf/mypy_protobuf/main.py +++ b/contrib/python/mypy-protobuf/mypy_protobuf/main.py @@ -24,7 +24,7 @@ from google.protobuf.internal.containers import RepeatedCompositeFieldContainer from google.protobuf.internal.well_known_types import WKTBASES from . import extensions_pb2 -__version__ = "3.5.0" +__version__ = "3.6.0" # SourceCodeLocation is defined by `message Location` here # https://github.com/protocolbuffers/protobuf/blob/master/src/google/protobuf/descriptor.proto @@ -169,9 +169,7 @@ class PkgWriter(object): """ if path == "typing_extensions": stabilization = { - "Literal": (3, 8), "TypeAlias": (3, 10), - "final": (3, 8), } assert name in stabilization if not self.typing_extensions_min or self.typing_extensions_min < stabilization[name]: @@ -407,7 +405,7 @@ class PkgWriter(object): class_name = desc.name if desc.name not in PYTHON_RESERVED else "_r_" + desc.name message_class = self._import("google.protobuf.message", "Message") - wl("@{}", self._import("typing_extensions", "final")) + wl("@{}", self._import("typing", "final")) wl(f"class {class_name}({message_class}{addl_base}):") with self._indent(): scl = scl_prefix + [i] @@ -438,12 +436,16 @@ class PkgWriter(object): if field.name in PYTHON_RESERVED: continue field_type = self.python_type(field) - if is_scalar(field) and field.label != d.FieldDescriptorProto.LABEL_REPEATED: # Scalar non repeated fields are r/w wl(f"{field.name}: {field_type}") self._write_comments(scl + [d.DescriptorProto.FIELD_FIELD_NUMBER, idx]) - else: + + for idx, field in enumerate(desc.field): + if field.name in PYTHON_RESERVED: + continue + field_type = self.python_type(field) + if not (is_scalar(field) and field.label != d.FieldDescriptorProto.LABEL_REPEATED): # r/o Getters for non-scalar fields and scalar-repeated fields scl_field = scl + [d.DescriptorProto.FIELD_FIELD_NUMBER, idx] wl("@property") @@ -452,6 +454,7 @@ class PkgWriter(object): if self._has_comments(scl_field): with self._indent(): self._write_comments(scl_field) + wl("") self.write_extensions(desc.extension, scl + [d.DescriptorProto.EXTENSION_FIELD_NUMBER]) @@ -506,14 +509,14 @@ class PkgWriter(object): if hf_fields: wl( "def HasField(self, field_name: {}[{}]) -> {}: ...", - self._import("typing_extensions", "Literal"), + self._import("typing", "Literal"), hf_fields_text, self._builtin("bool"), ) if cf_fields: wl( "def ClearField(self, field_name: {}[{}]) -> None: ...", - self._import("typing_extensions", "Literal"), + self._import("typing", "Literal"), cf_fields_text, ) @@ -522,10 +525,10 @@ class PkgWriter(object): wl("@{}", self._import("typing", "overload")) wl( "def WhichOneof(self, oneof_group: {}[{}]) -> {}[{}] | None: ...", - self._import("typing_extensions", "Literal"), + self._import("typing", "Literal"), # Accepts both str and bytes f'"{wo_field}", b"{wo_field}"', - self._import("typing_extensions", "Literal"), + self._import("typing", "Literal"), # Returns `str` ", ".join(f'"{m}"' for m in members), ) @@ -599,6 +602,7 @@ class PkgWriter(object): with self._indent(): if not self._write_comments(scl_method): wl("...") + wl("") def write_services( self, @@ -620,7 +624,6 @@ class PkgWriter(object): if self._write_comments(scl): wl("") self.write_methods(service, class_name, is_abstract=True, scl_prefix=scl) - wl("") # The stub client stub_class_name = service.name + "_Stub" @@ -633,7 +636,6 @@ class PkgWriter(object): self._import("google.protobuf.service", "RpcChannel"), ) self.write_methods(service, stub_class_name, is_abstract=False, scl_prefix=scl) - wl("") def _import_casttype(self, casttype: str) -> str: split = casttype.split(".") @@ -709,22 +711,20 @@ class PkgWriter(object): wl = self._write_line # _MaybeAsyncIterator[Req] is supertyped by Iterator[Req] and AsyncIterator[Req]. # So both can be used in the contravariant function parameter position. - wl("_T = {}('_T')", self._import("typing", "TypeVar")) + wl('_T = {}("_T")', self._import("typing", "TypeVar")) wl("") wl( - "class _MaybeAsyncIterator({}[_T], {}[_T], metaclass={}):", + "class _MaybeAsyncIterator({}[_T], {}[_T], metaclass={}): ...", self._import("collections.abc", "AsyncIterator"), self._import("collections.abc", "Iterator"), self._import("abc", "ABCMeta"), ) - with self._indent(): - wl("...") wl("") # _ServicerContext is supertyped by grpc.ServicerContext and grpc.aio.ServicerContext # So both can be used in the contravariant function parameter position. wl( - "class _ServicerContext({}, {}): # type: ignore", + "class _ServicerContext({}, {}): # type: ignore[misc, type-arg]", self._import("grpc", "ServicerContext"), self._import("grpc.aio", "ServicerContext"), ) @@ -758,6 +758,7 @@ class PkgWriter(object): with self._indent(): if not self._write_comments(scl): wl("...") + wl("") def write_grpc_stub_methods(self, service: d.ServiceDescriptorProto, scl_prefix: SourceCodeLocation, is_async: bool = False) -> None: wl = self._write_line @@ -774,6 +775,7 @@ class PkgWriter(object): wl("{},", self._output_type(method)) wl("]") self._write_comments(scl) + wl("") def write_grpc_services( self, @@ -799,7 +801,6 @@ class PkgWriter(object): channel = f"{self._import('typing', 'Union')}[{self._import('grpc', 'Channel')}, {self._import('grpc.aio', 'Channel')}]" wl("def __init__(self, channel: {}) -> None: ...", channel) self.write_grpc_stub_methods(service, scl) - wl("") # The (fake) async stub client wl( @@ -811,7 +812,6 @@ class PkgWriter(object): wl("") # No __init__ since this isn't a real class (yet), and requires manual casting to work. self.write_grpc_stub_methods(service, scl, is_async=True) - wl("") # The service definition interface wl( @@ -823,7 +823,6 @@ class PkgWriter(object): if self._write_comments(scl): wl("") self.write_grpc_methods(service, scl) - wl("") server = self._import("grpc", "Server") aserver = self._import("grpc.aio", "Server") wl( @@ -925,8 +924,9 @@ class PkgWriter(object): if self.lines: assert self.lines[0].startswith('"""') self.lines[0] = f'"""{HEADER}{self.lines[0][3:]}' + self._write_line("") else: - self._write_line(f'"""{HEADER}"""') + self._write_line(f'"""{HEADER}"""\n') for reexport_idx in self.fd.public_dependency: reexport_file = self.fd.dependency[reexport_idx] diff --git a/contrib/python/mypy-protobuf/ya.make b/contrib/python/mypy-protobuf/ya.make index 6ac24b9c93..efdb299b36 100644 --- a/contrib/python/mypy-protobuf/ya.make +++ b/contrib/python/mypy-protobuf/ya.make @@ -2,7 +2,7 @@ PY3_LIBRARY() -VERSION(3.5.0) +VERSION(3.6.0) LICENSE(Apache-2.0) |