Skip to content

Commit c2ecb77

Browse files
pcorpetsrittau
authored andcommitted
Add options and extensions to google protobuf messages. (#2589)
1 parent 23db1fc commit c2ecb77

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

third_party/2and3/google/protobuf/descriptor.pyi

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
from typing import Any
22

33
from .message import Message
4+
from .descriptor_pb2 import (
5+
EnumOptions,
6+
EnumValueOptions,
7+
FieldOptions,
8+
FileOptions,
9+
MessageOptions,
10+
MethodOptions,
11+
OneofOptions,
12+
ServiceOptions,
13+
)
414

515
class Error(Exception): ...
616
class TypeTransformationError(Error): ...
@@ -42,6 +52,7 @@ class Descriptor(_NestedDescriptorBase):
4252
def __init__(self, name, full_name, filename, containing_type, fields, nested_types, enum_types, extensions, options=..., is_extendable=..., extension_ranges=..., oneofs=..., file=..., serialized_start=..., serialized_end=..., syntax=...) -> None: ...
4353
def EnumValueName(self, enum, value): ...
4454
def CopyToProto(self, proto): ...
55+
def GetOptions(self) -> MessageOptions: ...
4556

4657
class FieldDescriptor(DescriptorBase):
4758
TYPE_DOUBLE = ... # type: Any
@@ -100,6 +111,7 @@ class FieldDescriptor(DescriptorBase):
100111
def __init__(self, name, full_name, index, number, type, cpp_type, label, default_value, message_type, enum_type, containing_type, is_extension, extension_scope, options=..., file=..., has_default_value=..., containing_oneof=...) -> None: ...
101112
@staticmethod
102113
def ProtoTypeToCppProtoType(proto_type): ...
114+
def GetOptions(self) -> FieldOptions: ...
103115

104116
class EnumDescriptor(_NestedDescriptorBase):
105117
def __new__(cls, name, full_name, filename, values, containing_type=..., options=..., file=..., serialized_start=..., serialized_end=...): ...
@@ -108,6 +120,7 @@ class EnumDescriptor(_NestedDescriptorBase):
108120
values_by_number = ... # type: Any
109121
def __init__(self, name, full_name, filename, values, containing_type=..., options=..., file=..., serialized_start=..., serialized_end=...) -> None: ...
110122
def CopyToProto(self, proto): ...
123+
def GetOptions(self) -> EnumOptions: ...
111124

112125
class EnumValueDescriptor(DescriptorBase):
113126
def __new__(cls, name, index, number, type=..., options=...): ...
@@ -116,6 +129,7 @@ class EnumValueDescriptor(DescriptorBase):
116129
number = ... # type: Any
117130
type = ... # type: Any
118131
def __init__(self, name, index, number, type=..., options=...) -> None: ...
132+
def GetOptions(self) -> EnumValueOptions: ...
119133

120134
class OneofDescriptor:
121135
def __new__(cls, name, full_name, index, containing_type, fields): ...
@@ -125,6 +139,7 @@ class OneofDescriptor:
125139
containing_type = ... # type: Any
126140
fields = ... # type: Any
127141
def __init__(self, name, full_name, index, containing_type, fields) -> None: ...
142+
def GetOptions(self) -> OneofOptions: ...
128143

129144
class ServiceDescriptor(_NestedDescriptorBase):
130145
index = ... # type: Any
@@ -133,6 +148,7 @@ class ServiceDescriptor(_NestedDescriptorBase):
133148
def __init__(self, name, full_name, index, methods, options=..., file=..., serialized_start=..., serialized_end=...) -> None: ...
134149
def FindMethodByName(self, name): ...
135150
def CopyToProto(self, proto): ...
151+
def GetOptions(self) -> ServiceOptions: ...
136152

137153
class MethodDescriptor(DescriptorBase):
138154
name = ... # type: Any
@@ -142,6 +158,7 @@ class MethodDescriptor(DescriptorBase):
142158
input_type = ... # type: Any
143159
output_type = ... # type: Any
144160
def __init__(self, name, full_name, index, containing_service, input_type, output_type, options=...) -> None: ...
161+
def GetOptions(self) -> MethodOptions: ...
145162

146163
class FileDescriptor(DescriptorBase):
147164
def __new__(cls, name, package, options=..., serialized_pb=..., dependencies=..., public_dependencies=..., syntax=..., pool=...): ...
@@ -159,6 +176,7 @@ class FileDescriptor(DescriptorBase):
159176
public_dependencies = ... # type: Any
160177
def __init__(self, name, package, options=..., serialized_pb=..., dependencies=..., public_dependencies=..., syntax=..., pool=...) -> None: ...
161178
def CopyToProto(self, proto): ...
179+
def GetOptions(self) -> FileOptions: ...
162180

163181
def MakeDescriptor(desc_proto, package=..., build_file_if_cpp=..., syntax=...): ...
164182
def _ParseOptions(message: Message, string: bytes) -> Message: ...

third_party/2and3/google/protobuf/message.pyi

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
from typing import Any, Sequence, Optional, Text, Tuple
22

3-
from .descriptor import FieldDescriptor
3+
from .descriptor import (
4+
DescriptorBase,
5+
FieldDescriptor,
6+
)
47

58
class Error(Exception): ...
69
class DecodeError(Error): ...
710
class EncodeError(Error): ...
811

12+
class _ExtensionDict:
13+
def __getitem__(self, extension_handle: DescriptorBase) -> Any: ...
14+
def __setitem__(self, extension_handle: DescriptorBase, value: Any) -> None: ...
15+
916
class Message:
1017
DESCRIPTOR = ... # type: Any
1118
def __deepcopy__(self, memo=...): ...
@@ -27,6 +34,8 @@ class Message:
2734
def HasExtension(self, extension_handle): ...
2835
def ClearExtension(self, extension_handle): ...
2936
def ByteSize(self) -> int: ...
37+
@property
38+
def Extensions(self) -> _ExtensionDict: ...
3039

3140
# TODO: check kwargs
3241
def __init__(self, **kwargs) -> None: ...

0 commit comments

Comments
 (0)