-
-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shorter syntax for optional field #63
Comments
Good point, but I need to think about it a little longer to come up with a good solution. The point is that @dataclass
class Foo:
bar: Optional[int] = 42 # nullable but default is not `None`
Foo(bar=None) # still can be set to `None`
Foo() # or use default `42`
Foo(bar=1) # or still provide a different value And this is not valid: @dataclass
class Foo:
bar: Optional[int]
Foo() # `bar` must be provided But I understand this is a common case to set optional an field to |
Could you pre-define the I'm working in an IoT project. To ease the collaboration with firmware developers, I have to keep a *.proto file. They will use some tool to generate to C code and I handcraft the Python code based on it. It would reduce mistake if there is also a tool to generate Python code (in case the proto changes a lot and I lost track). |
True, I'll add the |
New: #63 convenience method for an optional field
Sorry for the slow action, the function is now added |
Thank @eigenein |
In proto3, every fields are optional. But in Python code, to declare field as optional, I have to write long lines of code:
Not only do I have to wrap type with
Optional
, but also do I have to passdefault=None
tofield()
call.Do you have any idea to make it shorter and look not duplicate?
The text was updated successfully, but these errors were encountered: