Skip to content

Commit

Permalink
Supported repeated field containers for extensions
Browse files Browse the repository at this point in the history
See nipunn1313/mypy-protobuf#244 for the
inspiration for this. Repeated extensions are allowed by protobuf,
and they generate to extension values with repeated fields.

Notably map fields (ScalarMap and MessageMap) are NOT allowed to be
extension values - producing errors as such - so those are omitted.

testproto/test_extensions3.proto:19:6: Map fields are not allowed to be extensions.
  • Loading branch information
nipunn1313 committed Jul 16, 2021
1 parent a0f1997 commit 0b84267
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion stubs/protobuf/google/protobuf/internal/extension_dict.pyi
Original file line number Diff line number Diff line change
@@ -1,10 +1,23 @@
from typing import Any, Generic, Iterator, Text, TypeVar, Union

from google.protobuf.descriptor import FieldDescriptor
from google.protobuf.internal.containers import (
RepeatedScalarFieldContainer,
RepeatedCompositeFieldContainer,
)
from google.protobuf.message import Message

_ContainerMessageT = TypeVar("_ContainerMessageT", bound=Message)
_ExtenderMessageT = TypeVar("_ExtenderMessageT", bound=Union[Message, bool, int, float, Text, bytes])
_ExtenderMessageT = TypeVar("_ExtenderMessageT", bound=Union[
Message,
RepeatedScalarFieldContainer,
RepeatedCompositeFieldContainer,
bool,
int,
float,
Text,
bytes,
])

class _ExtensionFieldDescriptor(FieldDescriptor, Generic[_ContainerMessageT, _ExtenderMessageT]): ...

Expand Down

0 comments on commit 0b84267

Please sign in to comment.