Skip to content
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

Remove placeholders #641

Open
wants to merge 37 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
db56d13
Mark repeated fields
AdrienVannson Nov 8, 2024
c44b4ac
Regenerate files
AdrienVannson Nov 11, 2024
7138ff8
Remove placeholders
AdrienVannson Nov 11, 2024
f8e7e54
Fix groups in post_init
AdrienVannson Nov 11, 2024
2324c06
Fix test
AdrienVannson Nov 11, 2024
3574d6b
Fix bugs
AdrienVannson Nov 11, 2024
8fdea02
Fix test
AdrienVannson Nov 11, 2024
fa000bd
Right type for default values of enum fields
AdrienVannson Nov 11, 2024
bff2547
Fix default value for field in group
AdrienVannson Nov 11, 2024
f7f5162
Add repeated in message definition in tests
AdrienVannson Nov 11, 2024
1340bd8
Fix missing messages in to_dict and to_pydict
AdrienVannson Nov 11, 2024
a9ec707
Fix pickling tests
AdrienVannson Nov 11, 2024
a613dff
Fix placeholders in tests
AdrienVannson Nov 11, 2024
d3e17f4
Remove serialize_on_wire from condition
AdrienVannson Nov 11, 2024
d5701ab
Remove serialize_on_wire
AdrienVannson Nov 11, 2024
0936fb1
Remove serialize_on_wire tests
AdrienVannson Nov 12, 2024
fded4d3
Remove wrong test
AdrienVannson Nov 12, 2024
c9df9c1
Load test directly
AdrienVannson Nov 12, 2024
bc9d79e
Fix match test
AdrienVannson Nov 12, 2024
02e46f2
Fix README
AdrienVannson Nov 12, 2024
48c8fea
Add error (tofix)
AdrienVannson Nov 12, 2024
1258390
Fix to_dict / to_pydict test
AdrienVannson Nov 12, 2024
e09ec0c
Don't include default value in __repr__
AdrienVannson Nov 12, 2024
a3d55cc
Fix snake_case test
AdrienVannson Nov 12, 2024
2884b5a
Remove useless try / catch
AdrienVannson Nov 12, 2024
ba940f5
Manually add missing repeated parameters in compiled file
AdrienVannson Nov 12, 2024
8b7a947
Fix compilation errors
AdrienVannson Nov 12, 2024
fd0bf4c
Fix enum compilation
AdrienVannson Nov 12, 2024
5e65d4f
Compile fields in oneof as optional
AdrienVannson Nov 12, 2024
3d44dc2
Fix from_pydict
AdrienVannson Nov 12, 2024
1ed8da0
Remove Rust codec
AdrienVannson Nov 12, 2024
f5a5c8c
Mark messages as optional
AdrienVannson Nov 12, 2024
d4bd511
Format the code
AdrienVannson Nov 12, 2024
749d106
Move match test to other file
AdrienVannson Nov 12, 2024
f56f63d
Remoev useless prints
AdrienVannson Nov 13, 2024
64e6dc1
Remove serialized_on_wire from documentation
AdrienVannson Nov 13, 2024
df21b09
Simplify lambda functions
AdrienVannson Nov 15, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 3 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -248,20 +248,6 @@ For compatibility the default is to convert field names to `camelCase`. You can
MyMessage().to_dict(casing=betterproto.Casing.SNAKE)
```

### Determining if a message was sent

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.

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.

```py
# Old way (official Google Protobuf package)
>>> mymessage.HasField('myfield')

# New way (this project)
>>> betterproto.serialized_on_wire(mymessage.myfield)
```

### One-of Support

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:
Expand All @@ -283,11 +269,11 @@ On Python 3.10 and later, you can use a `match` statement to access the provided
```py
test = Test()
match test:
case Test(on=value):
case Test(on=bool(value)):
print(value) # value: bool
case Test(count=value):
case Test(count=int(value)):
print(value) # value: int
case Test(name=value):
case Test(name=str(value)):
print(value) # value: str
case _:
print("No value provided")
Expand Down
24 changes: 0 additions & 24 deletions docs/migrating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,6 @@ regenerating your protobufs of course) although there are some minor differences
:meth:`betterproto.Message.__bytes__` respectively.


Determining if a message was sent
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

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.

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.

.. code-block:: python

# Old way (official Google Protobuf package)
>>> mymessage.HasField('myfield')
True

# New way (this project)
>>> betterproto.serialized_on_wire(mymessage.myfield)
True


One-of Support
~~~~~~~~~~~~~~

Expand Down
895 changes: 471 additions & 424 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ packages = [

[tool.poetry.dependencies]
python = "^3.8"
black = { version = ">=23.1.0", optional = true }
black = { version = "=23.1.0", optional = true }
grpclib = "^0.4.1"
jinja2 = { version = ">=3.0.3", optional = true }
python-dateutil = "^2.8"
isort = { version = "^5.11.5", optional = true }
isort = { version = "=5.11.5", optional = true }
typing-extensions = "^4.7.1"
betterproto-rust-codec = { version = "0.1.1", optional = true }

Expand Down
Loading
Loading