Skip to content

Commit cf8c41f

Browse files
AdrienVannsonAdrien Vannson
andauthored
Remove placeholders (#2)
* Mark repeated fields * Regenerate files * Remove placeholders * Fix groups in post_init * Fix test * Fix bugs * Fix test * Right type for default values of enum fields * Fix default value for field in group * Add repeated in message definition in tests * Fix missing messages in to_dict and to_pydict * Fix pickling tests * Fix placeholders in tests * Remove serialize_on_wire from condition * Remove serialize_on_wire * Remove serialize_on_wire tests * Remove wrong test * Load test directly * Fix match test * Fix README * Add error (tofix) * Fix to_dict / to_pydict test * Don't include default value in __repr__ * Fix snake_case test * Remove useless try / catch * Manually add missing repeated parameters in compiled file * Fix compilation errors * Fix enum compilation * Compile fields in oneof as optional * Fix from_pydict * Remove Rust codec * Mark messages as optional * Format the code * Move match test to other file * Remoev useless prints * Remove serialized_on_wire from documentation * Simplify lambda functions * Format the code --------- Co-authored-by: Adrien Vannson <adrien.vannson@gardacp.com>
1 parent dd6d556 commit cf8c41f

File tree

20 files changed

+1965
-1916
lines changed

20 files changed

+1965
-1916
lines changed

README.md

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -248,20 +248,6 @@ For compatibility the default is to convert field names to `camelCase`. You can
248248
MyMessage().to_dict(casing=betterproto.Casing.SNAKE)
249249
```
250250

251-
### Determining if a message was sent
252-
253-
Sometimes it is useful to be able to determine whether a message has been sent on the wire. This is how the Google wrapper types work to let you know whether a value is unset, set as the default (zero value), or set as something else, for example.
254-
255-
Use `betterproto.serialized_on_wire(message)` to determine if it was sent. This is a little bit different from the official Google generated Python code, and it lives outside the generated `Message` class to prevent name clashes. Note that it **only** supports Proto 3 and thus can **only** be used to check if `Message` fields are set. You cannot check if a scalar was sent on the wire.
256-
257-
```py
258-
# Old way (official Google Protobuf package)
259-
>>> mymessage.HasField('myfield')
260-
261-
# New way (this project)
262-
>>> betterproto.serialized_on_wire(mymessage.myfield)
263-
```
264-
265251
### One-of Support
266252

267253
Protobuf supports grouping fields in a `oneof` clause. Only one of the fields in the group may be set at a given time. For example, given the proto:
@@ -283,11 +269,11 @@ On Python 3.10 and later, you can use a `match` statement to access the provided
283269
```py
284270
test = Test()
285271
match test:
286-
case Test(on=value):
272+
case Test(on=bool(value)):
287273
print(value) # value: bool
288-
case Test(count=value):
274+
case Test(count=int(value)):
289275
print(value) # value: int
290-
case Test(name=value):
276+
case Test(name=str(value)):
291277
print(value) # value: str
292278
case _:
293279
print("No value provided")

docs/migrating.rst

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,6 @@ regenerating your protobufs of course) although there are some minor differences
1919
:meth:`betterproto.Message.__bytes__` respectively.
2020

2121

22-
Determining if a message was sent
23-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
24-
25-
Sometimes it is useful to be able to determine whether a message has been sent on
26-
the wire. This is how the Google wrapper types work to let you know whether a value is
27-
unset (set as the default/zero value), or set as something else, for example.
28-
29-
Use ``betterproto.serialized_on_wire(message)`` to determine if it was sent. This is
30-
a little bit different from the official Google generated Python code, and it lives
31-
outside the generated ``Message`` class to prevent name clashes. Note that it only
32-
supports Proto 3 and thus can only be used to check if ``Message`` fields are set.
33-
You cannot check if a scalar was sent on the wire.
34-
35-
.. code-block:: python
36-
37-
# Old way (official Google Protobuf package)
38-
>>> mymessage.HasField('myfield')
39-
True
40-
41-
# New way (this project)
42-
>>> betterproto.serialized_on_wire(mymessage.myfield)
43-
True
44-
45-
4622
One-of Support
4723
~~~~~~~~~~~~~~
4824

poetry.lock

Lines changed: 203 additions & 165 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)