Skip to content

Commit 7e3e221

Browse files
Add a field metadata indicating if the field is repeated (#46)
* Add a field metadata indicating if the field is repeated * Increase version number
1 parent 7598307 commit 7e3e221

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "betterproto2"
3-
version = "0.1.1"
3+
version = "0.1.2"
44
description = "A better Protobuf / gRPC generator & library"
55
authors = ["Adrien Vannson <[email protected]>", "Daniel G. Taylor <[email protected]>"]
66
readme = "README.md"

src/betterproto2/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ class FieldMetadata:
185185
wraps: Optional[str] = None
186186
# Is the field optional
187187
optional: Optional[bool] = False
188+
# Is the field repeated
189+
repeated: Optional[bool] = False
188190

189191
@staticmethod
190192
def get(field: dataclasses.Field) -> "FieldMetadata":
@@ -234,7 +236,7 @@ def field(
234236

235237
return dataclasses.field(
236238
default_factory=default_factory,
237-
metadata={"betterproto": FieldMetadata(number, proto_type, map_types, group, wraps, optional)},
239+
metadata={"betterproto": FieldMetadata(number, proto_type, map_types, group, wraps, optional, repeated)},
238240
)
239241

240242

@@ -962,9 +964,8 @@ def to_dict(self, casing: Casing = Casing.CAMEL, include_default_values: bool =
962964
"""
963965
output: Dict[str, Any] = {}
964966
field_types = self._type_hints()
965-
defaults = self._betterproto.default_gen
966967
for field_name, meta in self._betterproto.meta_by_field_name.items():
967-
field_is_repeated = defaults[field_name] is list
968+
field_is_repeated = meta.repeated
968969
value = getattr(self, field_name)
969970
cased_name = casing(field_name).rstrip("_") # type: ignore
970971
if meta.proto_type == TYPE_MESSAGE:
@@ -1204,9 +1205,8 @@ def to_pydict(self, casing: Casing = Casing.CAMEL, include_default_values: bool
12041205
The python dict representation of this object.
12051206
"""
12061207
output: Dict[str, Any] = {}
1207-
defaults = self._betterproto.default_gen
12081208
for field_name, meta in self._betterproto.meta_by_field_name.items():
1209-
field_is_repeated = defaults[field_name] is list
1209+
field_is_repeated = meta.repeated
12101210
value = getattr(self, field_name)
12111211
cased_name = casing(field_name).rstrip("_") # type: ignore
12121212
if meta.proto_type == TYPE_MESSAGE:

0 commit comments

Comments
 (0)