Skip to content

Commit fe85fcd

Browse files
committed
Fixed and improved stub for google.protobuf.internal.enum_type_wrapper module
1 parent 4d86092 commit fe85fcd

16 files changed

+484
-1000
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ from google.protobuf.source_context_pb2 import (
99
)
1010
from google.protobuf.type_pb2 import (
1111
Option,
12-
Syntax,
12+
_Syntax,
1313
)
1414
from typing import (
1515
Iterable,
@@ -21,7 +21,7 @@ from typing import (
2121
class Api(Message):
2222
name = ... # type: Text
2323
version = ... # type: Text
24-
syntax = ... # type: Syntax
24+
syntax = ... # type: _Syntax
2525

2626
@property
2727
def methods(self) -> RepeatedCompositeFieldContainer[Method]: ...
@@ -42,7 +42,7 @@ class Api(Message):
4242
version: Optional[Text] = ...,
4343
source_context: Optional[SourceContext] = ...,
4444
mixins: Optional[Iterable[Mixin]] = ...,
45-
syntax: Optional[Syntax] = ...,
45+
syntax: Optional[_Syntax] = ...,
4646
) -> None: ...
4747

4848
@classmethod
@@ -55,7 +55,7 @@ class Method(Message):
5555
request_streaming = ... # type: bool
5656
response_type_url = ... # type: Text
5757
response_streaming = ... # type: bool
58-
syntax = ... # type: Syntax
58+
syntax = ... # type: _Syntax
5959

6060
@property
6161
def options(self) -> RepeatedCompositeFieldContainer[Option]: ...
@@ -67,7 +67,7 @@ class Method(Message):
6767
response_type_url: Optional[Text] = ...,
6868
response_streaming: Optional[bool] = ...,
6969
options: Optional[Iterable[Option]] = ...,
70-
syntax: Optional[Syntax] = ...,
70+
syntax: Optional[_Syntax] = ...,
7171
) -> None: ...
7272

7373
@classmethod

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

Lines changed: 65 additions & 143 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from google.protobuf.internal.enum_type_wrapper import (
2+
EnumTypeWrapper,
3+
)
14
from google.protobuf.internal.containers import (
25
RepeatedCompositeFieldContainer,
36
RepeatedScalarFieldContainer,
@@ -12,6 +15,7 @@ from typing import (
1215
Text,
1316
Tuple,
1417
cast,
18+
NewType,
1519
)
1620

1721

@@ -171,66 +175,38 @@ class ExtensionRangeOptions(Message):
171175
def FromString(cls, s: bytes) -> ExtensionRangeOptions: ...
172176

173177

174-
class FieldDescriptorProto(Message):
178+
_FieldDescriptorProto_Type = NewType('_FieldDescriptorProto_Type', int)
179+
_FieldDescriptorProto_Label = NewType('_FieldDescriptorProto_Label', int)
175180

176-
class Type(int):
177181

178-
@classmethod
179-
def Name(cls, number: int) -> bytes: ...
180-
181-
@classmethod
182-
def Value(cls, name: bytes) -> FieldDescriptorProto.Type: ...
183-
184-
@classmethod
185-
def keys(cls) -> List[bytes]: ...
186-
187-
@classmethod
188-
def values(cls) -> List[FieldDescriptorProto.Type]: ...
189-
190-
@classmethod
191-
def items(cls) -> List[Tuple[bytes, FieldDescriptorProto.Type]]: ...
192-
TYPE_DOUBLE: Type
193-
TYPE_FLOAT: Type
194-
TYPE_INT64: Type
195-
TYPE_UINT64: Type
196-
TYPE_INT32: Type
197-
TYPE_FIXED64: Type
198-
TYPE_FIXED32: Type
199-
TYPE_BOOL: Type
200-
TYPE_STRING: Type
201-
TYPE_GROUP: Type
202-
TYPE_MESSAGE: Type
203-
TYPE_BYTES: Type
204-
TYPE_UINT32: Type
205-
TYPE_ENUM: Type
206-
TYPE_SFIXED32: Type
207-
TYPE_SFIXED64: Type
208-
TYPE_SINT32: Type
209-
TYPE_SINT64: Type
210-
211-
class Label(int):
212-
213-
@classmethod
214-
def Name(cls, number: int) -> bytes: ...
215-
216-
@classmethod
217-
def Value(cls, name: bytes) -> FieldDescriptorProto.Label: ...
218-
219-
@classmethod
220-
def keys(cls) -> List[bytes]: ...
221-
222-
@classmethod
223-
def values(cls) -> List[FieldDescriptorProto.Label]: ...
224-
225-
@classmethod
226-
def items(cls) -> List[Tuple[bytes, FieldDescriptorProto.Label]]: ...
227-
LABEL_OPTIONAL: Label
228-
LABEL_REQUIRED: Label
229-
LABEL_REPEATED: Label
182+
class FieldDescriptorProto(Message):
183+
Type: EnumTypeWrapper[_FieldDescriptorProto_Type]
184+
TYPE_DOUBLE: _FieldDescriptorProto_Type
185+
TYPE_FLOAT: _FieldDescriptorProto_Type
186+
TYPE_INT64: _FieldDescriptorProto_Type
187+
TYPE_UINT64: _FieldDescriptorProto_Type
188+
TYPE_INT32: _FieldDescriptorProto_Type
189+
TYPE_FIXED64: _FieldDescriptorProto_Type
190+
TYPE_FIXED32: _FieldDescriptorProto_Type
191+
TYPE_BOOL: _FieldDescriptorProto_Type
192+
TYPE_STRING: _FieldDescriptorProto_Type
193+
TYPE_GROUP: _FieldDescriptorProto_Type
194+
TYPE_MESSAGE: _FieldDescriptorProto_Type
195+
TYPE_BYTES: _FieldDescriptorProto_Type
196+
TYPE_UINT32: _FieldDescriptorProto_Type
197+
TYPE_ENUM: _FieldDescriptorProto_Type
198+
TYPE_SFIXED32: _FieldDescriptorProto_Type
199+
TYPE_SFIXED64: _FieldDescriptorProto_Type
200+
TYPE_SINT32: _FieldDescriptorProto_Type
201+
TYPE_SINT64: _FieldDescriptorProto_Type
202+
Label: EnumTypeWrapper[_FieldDescriptorProto_Label]
203+
LABEL_OPTIONAL: _FieldDescriptorProto_Label
204+
LABEL_REQUIRED: _FieldDescriptorProto_Label
205+
LABEL_REPEATED: _FieldDescriptorProto_Label
230206
name = ... # type: Text
231207
number = ... # type: int
232-
label = ... # type: FieldDescriptorProto.Label
233-
type = ... # type: FieldDescriptorProto.Type
208+
label = ... # type: _FieldDescriptorProto_Label
209+
type = ... # type: _FieldDescriptorProto_Type
234210
type_name = ... # type: Text
235211
extendee = ... # type: Text
236212
default_value = ... # type: Text
@@ -243,8 +219,8 @@ class FieldDescriptorProto(Message):
243219
def __init__(self,
244220
name: Optional[Text] = ...,
245221
number: Optional[int] = ...,
246-
label: Optional[FieldDescriptorProto.Label] = ...,
247-
type: Optional[FieldDescriptorProto.Type] = ...,
222+
label: Optional[_FieldDescriptorProto_Label] = ...,
223+
type: Optional[_FieldDescriptorProto_Type] = ...,
248224
type_name: Optional[Text] = ...,
249225
extendee: Optional[Text] = ...,
250226
default_value: Optional[Text] = ...,
@@ -372,33 +348,20 @@ class MethodDescriptorProto(Message):
372348
def FromString(cls, s: bytes) -> MethodDescriptorProto: ...
373349

374350

375-
class FileOptions(Message):
376-
377-
class OptimizeMode(int):
378-
379-
@classmethod
380-
def Name(cls, number: int) -> bytes: ...
381-
382-
@classmethod
383-
def Value(cls, name: bytes) -> FileOptions.OptimizeMode: ...
384-
385-
@classmethod
386-
def keys(cls) -> List[bytes]: ...
351+
_FileOptions_OptimizeMode = NewType('_FileOptions_OptimizeMode', int)
387352

388-
@classmethod
389-
def values(cls) -> List[FileOptions.OptimizeMode]: ...
390353

391-
@classmethod
392-
def items(cls) -> List[Tuple[bytes, FileOptions.OptimizeMode]]: ...
393-
SPEED: OptimizeMode
394-
CODE_SIZE: OptimizeMode
395-
LITE_RUNTIME: OptimizeMode
354+
class FileOptions(Message):
355+
OptimizeMode: EnumTypeWrapper[_FileOptions_OptimizeMode]
356+
SPEED: _FileOptions_OptimizeMode
357+
CODE_SIZE: _FileOptions_OptimizeMode
358+
LITE_RUNTIME: _FileOptions_OptimizeMode
396359
java_package = ... # type: Text
397360
java_outer_classname = ... # type: Text
398361
java_multiple_files = ... # type: bool
399362
java_generate_equals_and_hash = ... # type: bool
400363
java_string_check_utf8 = ... # type: bool
401-
optimize_for = ... # type: FileOptions.OptimizeMode
364+
optimize_for = ... # type: _FileOptions_OptimizeMode
402365
go_package = ... # type: Text
403366
cc_generic_services = ... # type: bool
404367
java_generic_services = ... # type: bool
@@ -422,7 +385,7 @@ class FileOptions(Message):
422385
java_multiple_files: Optional[bool] = ...,
423386
java_generate_equals_and_hash: Optional[bool] = ...,
424387
java_string_check_utf8: Optional[bool] = ...,
425-
optimize_for: Optional[FileOptions.OptimizeMode] = ...,
388+
optimize_for: Optional[_FileOptions_OptimizeMode] = ...,
426389
go_package: Optional[Text] = ...,
427390
cc_generic_services: Optional[bool] = ...,
428391
java_generic_services: Optional[bool] = ...,
@@ -464,50 +427,22 @@ class MessageOptions(Message):
464427
def FromString(cls, s: bytes) -> MessageOptions: ...
465428

466429

467-
class FieldOptions(Message):
468-
469-
class CType(int):
430+
_FieldOptions_CType = NewType('_FieldOptions_CType', int)
431+
_FieldOptions_JSType = NewType('_FieldOptions_JSType', int)
470432

471-
@classmethod
472-
def Name(cls, number: int) -> bytes: ...
473-
474-
@classmethod
475-
def Value(cls, name: bytes) -> FieldOptions.CType: ...
476-
477-
@classmethod
478-
def keys(cls) -> List[bytes]: ...
479-
480-
@classmethod
481-
def values(cls) -> List[FieldOptions.CType]: ...
482433

483-
@classmethod
484-
def items(cls) -> List[Tuple[bytes, FieldOptions.CType]]: ...
485-
STRING: CType
486-
CORD: CType
487-
STRING_PIECE: CType
488-
489-
class JSType(int):
490-
491-
@classmethod
492-
def Name(cls, number: int) -> bytes: ...
493-
494-
@classmethod
495-
def Value(cls, name: bytes) -> FieldOptions.JSType: ...
496-
497-
@classmethod
498-
def keys(cls) -> List[bytes]: ...
499-
500-
@classmethod
501-
def values(cls) -> List[FieldOptions.JSType]: ...
502-
503-
@classmethod
504-
def items(cls) -> List[Tuple[bytes, FieldOptions.JSType]]: ...
505-
JS_NORMAL: JSType
506-
JS_STRING: JSType
507-
JS_NUMBER: JSType
508-
ctype = ... # type: FieldOptions.CType
434+
class FieldOptions(Message):
435+
CType: EnumTypeWrapper[_FieldOptions_CType]
436+
STRING: _FieldOptions_CType
437+
CORD: _FieldOptions_CType
438+
STRING_PIECE: _FieldOptions_CType
439+
JSType: EnumTypeWrapper[_FieldOptions_JSType]
440+
JS_NORMAL: _FieldOptions_JSType
441+
JS_STRING: _FieldOptions_JSType
442+
JS_NUMBER: _FieldOptions_JSType
443+
ctype = ... # type: _FieldOptions_CType
509444
packed = ... # type: bool
510-
jstype = ... # type: FieldOptions.JSType
445+
jstype = ... # type: _FieldOptions_JSType
511446
lazy = ... # type: bool
512447
deprecated = ... # type: bool
513448
weak = ... # type: bool
@@ -517,9 +452,9 @@ class FieldOptions(Message):
517452
self) -> RepeatedCompositeFieldContainer[UninterpretedOption]: ...
518453

519454
def __init__(self,
520-
ctype: Optional[FieldOptions.CType] = ...,
455+
ctype: Optional[_FieldOptions_CType] = ...,
521456
packed: Optional[bool] = ...,
522-
jstype: Optional[FieldOptions.JSType] = ...,
457+
jstype: Optional[_FieldOptions_JSType] = ...,
523458
lazy: Optional[bool] = ...,
524459
deprecated: Optional[bool] = ...,
525460
weak: Optional[bool] = ...,
@@ -594,37 +529,24 @@ class ServiceOptions(Message):
594529
def FromString(cls, s: bytes) -> ServiceOptions: ...
595530

596531

597-
class MethodOptions(Message):
598-
599-
class IdempotencyLevel(int):
600-
601-
@classmethod
602-
def Name(cls, number: int) -> bytes: ...
603-
604-
@classmethod
605-
def Value(cls, name: bytes) -> MethodOptions.IdempotencyLevel: ...
606-
607-
@classmethod
608-
def keys(cls) -> List[bytes]: ...
532+
_MethodOptions_IdempotencyLevel = NewType('_MethodOptions_IdempotencyLevel', int)
609533

610-
@classmethod
611-
def values(cls) -> List[MethodOptions.IdempotencyLevel]: ...
612534

613-
@classmethod
614-
def items(cls) -> List[Tuple[bytes, MethodOptions.IdempotencyLevel]]: ...
615-
IDEMPOTENCY_UNKNOWN: IdempotencyLevel
616-
NO_SIDE_EFFECTS: IdempotencyLevel
617-
IDEMPOTENT: IdempotencyLevel
535+
class MethodOptions(Message):
536+
IdempotencyLevel: EnumTypeWrapper[_MethodOptions_IdempotencyLevel]
537+
IDEMPOTENCY_UNKNOWN: _MethodOptions_IdempotencyLevel
538+
NO_SIDE_EFFECTS: _MethodOptions_IdempotencyLevel
539+
IDEMPOTENT: _MethodOptions_IdempotencyLevel
618540
deprecated = ... # type: bool
619-
idempotency_level = ... # type: MethodOptions.IdempotencyLevel
541+
idempotency_level = ... # type: _MethodOptions_IdempotencyLevel
620542

621543
@property
622544
def uninterpreted_option(
623545
self) -> RepeatedCompositeFieldContainer[UninterpretedOption]: ...
624546

625547
def __init__(self,
626548
deprecated: Optional[bool] = ...,
627-
idempotency_level: Optional[MethodOptions.IdempotencyLevel] = ...,
549+
idempotency_level: Optional[_MethodOptions_IdempotencyLevel] = ...,
628550
uninterpreted_option: Optional[Iterable[UninterpretedOption]] = ...,
629551
) -> None: ...
630552

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import Any, List, Tuple
1+
from typing import Any, List, Tuple, TypeVar, Generic
22

3-
class EnumTypeWrapper(object):
4-
def __init__(self, enum_type: Any) -> None: ...
5-
def Name(self, number: int) -> bytes: ...
6-
def Value(self, name: bytes) -> int: ...
7-
def keys(self) -> List[bytes]: ...
8-
def values(self) -> List[int]: ...
3+
_T = TypeVar("_T")
94

10-
@classmethod
11-
def items(cls) -> List[Tuple[bytes, int]]: ...
5+
class EnumTypeWrapper(Generic[_T]):
6+
def __init__(self, enum_type: Any) -> None: ...
7+
def Name(self, number: _T) -> str: ...
8+
def Value(self, name: str) -> _T: ...
9+
def keys(self) -> List[str]: ...
10+
def values(self) -> List[_T]: ...
11+
def items(self) -> List[Tuple[str, _T]]: ...

0 commit comments

Comments
 (0)