55 Commits

Author SHA1 Message Date
Adrien
f41934a0e2
Use ruff instead of black+isort (#644)
* Use ruff

* Update .gitignore

* Format code

* Use Ruff on generated code

* Update pre-commit hook

* Wrong commit

* Remove wrong imports

* Update hook

* Format code

* Target Python 3.8

* Reformat

* Pin ruff version
2025-01-03 01:59:43 +00:00
Adrien
8fdcb381b7
Prevent users from creating messages with wrong parameters when pydantic is used (#615) 2024-09-12 18:34:47 +01:00
Ajit Krishna
1538e156a1
Bump version to 2.0.0b7 (#593)
* Bump version to 2.0.0b7

* chore: changes to changelog from PR comments

* chore: grammar fix

* Add entry for #596

* Apply suggestions from code review

---------

Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2024-08-14 22:16:59 +01:00
Nicholas Gates
5fdd0bb24f
Update to Pydantic V2 (#588)
* Pydantic V2 support

* Support Python 3.8

* Mark as classmethod

* Remove max int validation

* Run poe format

* Merge develop

* Revert dataclasses import

* Fix revert
2024-07-23 14:43:31 +01:00
Ian McDonald
7c6c627938
Drop 3.7 from ci (#587)
* Drop 3.7 from ci

Currently, CI is broken for 3.7 as github runs its macos images on arm and doesn't provide arm images for 3.7.  As 3.7 is deprecated the best (at least interim) solution would be to drop 3.7 checks entirely.
2024-07-19 15:44:14 +10:00
Erik Friese
1f88b67eeb
betterproto-rust-codec updated (#571) 2024-04-13 15:16:33 +01:00
Maple
c3c20556e0
fix: support pydantic-version google pb (#568)
* feat: pydantic version of google pb

* fix: patch pb Struct to support json, dict rountrip

* fix: pydantic-version google pb, json, dict rntrip

* chore: remove `@generated`, remove gen, code fmt

* chore: test case for pydantic-version google pb
2024-04-08 23:54:36 +01:00
Erik Friese
d34b16993d
Use external package betterproto-rust-codec for better (de-)serialization performance (#545)
* optionally use betterproto-rust-codec
* monkey patch `parse` and `__bytes__`
2023-12-07 11:21:29 +11:00
Joshua Leivers
24db53290e
Fix Tox to use Poetry hermetically (#531) 2023-10-17 14:56:58 +01:00
Vasilios
ca6b9fe1a2
Implementing pickle methods (#535)
Continuing work from #484 by @kevinaud to fix #419

* Implementing pickle methods
* Implement __copy__, __reduce__, and fix __setstate__
* Moved pickling tests into their own file
* Add test for caching
2023-10-16 22:17:15 +11:00
James Hilton-Balfe
e3b44f491f
Fix timestamp parsing (#415)
Fixes #407
2023-10-16 13:35:32 +11:00
James Hilton-Balfe
c82816b8be
Map enum int's into Enums redux (#293)
Re-implement Enum to be faster along with being an open set

---------
Co-authored-by: ydylla <ydylla@gmail.com>
2023-10-16 13:32:30 +11:00
Alexander Khabarov
6faac1d1ca
Raise AttributeError on attempts to access unset oneof fields (#510) 2023-07-21 13:26:30 +01:00
Ashwin Madavan
098989e9e9
Bump version to 2.0.0b6 (#500)
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2023-06-26 00:12:49 +01:00
Alexander Khabarov
73d1fa3d5b
Upgrade grpcio-tools and protobuf (#498) 2023-06-24 19:39:11 +01:00
pi-slh
aad7d2ad76
Replace pkg_resources with importlib (#462) 2023-05-25 11:12:15 +01:00
Samuel Yvon
13d656587c
Add support for pydantic dataclasses (#406) 2023-02-13 15:37:16 +00:00
James Hilton-Balfe
6df8cef3f0
Fix CI (#456) 2023-02-13 00:20:58 +00:00
James Hilton-Balfe
1b1bd47cb1
Drop support for python3.6 (#444) 2023-02-09 08:35:41 +00:00
James Hilton-Balfe
496eba2750
Bump version to b5 (#404) 2022-08-02 09:23:44 +10:00
Justin Torre
2fb37dd108
Update Jinja 2 version (#402) 2022-08-01 10:44:37 +01:00
Arun Babu Neelicattu
1aaf7728cc
compiler: Run isort on compiled code (#355) 2022-03-18 22:29:42 +00:00
Arun Babu Neelicattu
70310c9e8c
pre-commit: add isort hook and apply (#354) 2022-03-17 00:01:17 +00:00
Arun Babu Neelicattu
a836fb23bc
Configure pre-commit for project (#346) 2022-03-03 18:10:01 +00:00
Eitan Mosenkis
eeddc844a5
Bump Jinja2 to 3.0.3. (#330) 2022-02-01 08:32:25 +00:00
efokschaner
d260f071e0
Client and Service Stubs take 1 request parameter, not one for each field (#311) 2022-01-17 19:58:57 +01:00
James Hilton-Balfe
6dd7baa26c
Release v2.0.0.b4 (#307)
Co-authored-by: Kalan <22137047+kalzoo@users.noreply.github.com>
2022-01-03 18:18:44 +00:00
Kalan
573c7292a6
Add Python 3.10 to GitHub Actions test matrix (#280)
Co-authored-by: James Hilton-Balfe <50501825+Gobot1234@users.noreply.github.com>
2021-12-29 23:10:34 +00:00
Kalan
d77f44ebb7
Support proto3 field presence (#281)
* Update protobuf pregenerated files

* Update grpcio-tools to latest version

* Implement proto3 field presence

* Fix to_dict with None optional fields.

* Add test with optional enum

* Properly support optional enums

* Add tests for 64-bit ints and floats

* Support field presence for int64 types

* Fix oneof serialization with proto3 field presence (#292)

= Description

The serialization of a oneof message that contains a message with fields
with explicit presence was buggy.

For example:

```
message A {
    oneof kind {
        B b = 1;
        C c = 2;
    }
}

message B {}
message C {
    optional bool z = 1;
}
```

Serializing `A(b=B())` would lead to this payload:

```
0A # tag1, length delimited
00 # length: 0
12 # tag2, length delimited
00 # length: 0
```

Which when deserialized, leads to the message `A(c=C())`.

= Explanation

The issue lies in the post_init method. All fields are introspected, and
if different from PLACEHOLDER, the message is marked as having been
"serialized_on_wire".
Then, when serializing `A(b=B())`, we go through each field of the
oneof:

- field 'b': this is the selected field from the group, so it is
  serialized
- field 'c': marked as 'serialized_on_wire', so it is added as well.

= Fix

The issue is that support for explicit presence changed the default
value from PLACEHOLDER to None. This breaks the post_init method in that
case, which is relatively easy to fix: if a field is optional, and set
to None, this is considered as the default value (which it is).

This fix however has a side-effect: the group_current for this field (the
oneof trick for explicit presence) is no longer set. This changes the
behavior when serializing the message in JSON: as the value is the
default one (None), and the group is not set (which would force the
serialization of the field), so None fields are no longer serialized in
JSON. This break one test, and will be fixed in the next commit.

* fix: do not serialize None fields in JSON format

This is linked to the fix from the previous commit: after it, scalar
None fields were not included in the JSON format, but some were still
included.

This is all cleaned up: None fields are not added in JSON by default,
as they indicate the default value of fields with explicit presence.
However, if `include_default_values is set, they are included.

* Fix: use builtin annotation prefix

* Remove comment

Co-authored-by: roblabla <unfiltered@roblab.la>
Co-authored-by: Vincent Thiberville <vthib@pm.me>
2021-12-29 13:38:32 -08:00
Kalan
a4d2d39546
Fix Python 3.9 Tests (#284)
Co-authored-by: James Hilton-Balfe <50501825+Gobot1234@users.noreply.github.com>
2021-11-19 21:32:36 +00:00
nat
02e41afd09
Release v2.0.0b3 (#182)
Updated change log to include all new features and fixes from master.
2021-04-07 12:57:44 +02:00
nat
95339bf74d
Misc cleanup, see commit body (#227)
- Enable oneof_enum test case that passes now (removed the xfail)
- Switch from toml to tomlkit as a dev dep for better toml support
- upgrade poethepoet to latest stable release
- use full table format for poe tasks to avoid long lines in pyproject.toml
- remove redundant _WrappedMessage class
- fix various Mypy warnings
- reformat some comments for consistent line length
2021-04-06 10:43:09 +10:00
Nat Noordanus
a890514b5c Update deps & add generate_lib task
- Remove plugin dependency on protobuf since it's no longer required.
- Update poethepoet to for better pyproject toml syntax support
- Add handy generate_lib poe task for maintaining generated libs
2021-04-01 09:49:22 +11:00
Vasili Syrakis
7a358a63cf Add __version__ attribute to package 2021-03-31 11:44:32 +11:00
nat
342e6559dc
Properly serialize zero-value messages in a oneof group (#176)
Also improve test utils to make it easier to have multiple json examples.

Co-authored-by: Christopher Chambers <chris@peanutcode.com>
2021-03-15 13:52:35 +01:00
robinaly
6c1c41e9cc
Use dateutil parser (#213)
Switch to using `isoparse` from `dateutil.parser` instead of `datetime.fromisoformat` for more robust parsing of dates in from_dict.
2021-02-24 22:18:05 +01:00
Arun Babu Neelicattu
a157f05480
Release v2.0.0b2 (#175) 2020-11-24 23:04:33 +01:00
Arun Babu Neelicattu
bf9412e083
Use poetry-core as PEP 517 build backend (#108)
This change replaces the use of poetry as the build backend in favour
of the leaner poetry-core. This speeds up PEP-517 builds for source
installs, tox environment setup etc.
2020-10-01 14:45:45 +02:00
Keerthan Jaic
4630c1cc67
bump grpclib to 0.4.1 (#150) 2020-09-23 21:55:23 +02:00
James
d3e4fbb311
Add Documentation (#125)
Add sphinx docs with readthedocs integration.

Docs can be built locally with `poe docs`.
2020-09-20 22:00:02 +02:00
Adrian Garcia Badaracco
a3f5f21738
Add benchmarks (#148)
Add asv based benchmarks to guide future optimisation work.
2020-09-19 16:28:16 +02:00
Arun Babu Neelicattu
0028cc384a
Relax black version constraints (#146)
This change ensures that the wheel built only requests for the minimum
version of black it requires to function as intended. Without this
change any project that uses betterproto[compiler] would break while
resolving dependencies.
2020-08-31 22:10:57 +02:00
James
16d554db75
Update black 2020-08-29 17:15:59 +02:00
nat
804805f0f5
Update poe (#132)
- This update improves support for windows & removes the direct dependency on poetry
2020-08-06 22:16:25 +02:00
nat
c513853301
Replace Makefile with poe tasks in pyproject.yaml (#118)
https://github.com/nat-n/poethepoet
2020-07-25 19:54:40 +02:00
Arun Babu Neelicattu
0ba0692dec Handle mutable default arguments cleanly
When generating code, ensure that default list/dict arguments are
initialised in local scope if unspecified or `None`.
2020-07-11 22:33:44 +02:00
Arun Babu Neelicattu
459d12b24d Move betterproto → src/betterproto
This change avoids some nasty import issues and also ensures that the
right code is tested and arbitrary code is not included when packaging.
2020-07-11 19:51:01 +02:00
Arun Babu Neelicattu
03211604bc Replace dependency on protoc with grpcio-tools
This change removes the dependency on platform provided protobuf tools
in favour of `grpcio-tools` dependency. This makes both development and
compiler use independent from platform dependencies.
2020-07-10 13:16:40 +02:00
boukeversteegh
eaa4f7f5d9 Release v2.0.0b1 2020-07-04 14:00:35 +02:00
boukeversteegh
0d9387abec Remove stringcase dependency 2020-07-01 12:43:12 +02:00