optional support
This commit is contained in:
parent
d1825026db
commit
df0c17bf0a
@ -68,6 +68,8 @@ fn create_cached_descriptor_in_pool<'py>(
|
||||
|
||||
if meta.is_list_field(field_name)? {
|
||||
field.set_label(Label::Repeated);
|
||||
} else if field_meta.getattr("optional")?.extract::<bool>()? {
|
||||
field.proto3_optional = Some(true);
|
||||
}
|
||||
|
||||
if let Some(grp) = meta.oneof_group(field_name)? {
|
||||
|
@ -3,7 +3,7 @@
|
||||
|
||||
import betterproto
|
||||
from dataclasses import dataclass
|
||||
from typing import List
|
||||
from typing import List, Optional
|
||||
|
||||
@dataclass(repr=False)
|
||||
class Baz(betterproto.Message):
|
||||
@ -11,6 +11,7 @@ class Baz(betterproto.Message):
|
||||
b: int = betterproto.int64_field(2, group = "x")
|
||||
c: float = betterproto.float_field(3, group = "y")
|
||||
d: int = betterproto.int64_field(4, group = "y")
|
||||
e: Optional[int] = betterproto.int32_field(5, group = "_e", optional = True)
|
||||
|
||||
@dataclass(repr=False)
|
||||
class Foo(betterproto.Message):
|
||||
@ -28,7 +29,7 @@ class Bar(betterproto.Message):
|
||||
buffer = bytes(
|
||||
Bar(
|
||||
foo1=Foo(1, 2.34),
|
||||
foo2=Foo(3, 4.56, [Baz(a = 1.234), Baz(b = 5), Baz(b = 2, d = 3)]),
|
||||
foo2=Foo(3, 4.56, [Baz(a = 1.234), Baz(b = 5, e=1), Baz(b = 2, d = 3)]),
|
||||
packed=[5, 3, 1]
|
||||
)
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user