40 Commits

Author SHA1 Message Date
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
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
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
d663a318b7
Release v.2.0.0b5 (#350)
* Implement Message.__bool__ for #130
* Add __bool__ to special members
* Tweak __bool__ docstring
* remove compiler: prefix

Co-authored-by: nat <n@natn.me>
2022-08-02 08:59: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
a836fb23bc
Configure pre-commit for project (#346) 2022-03-03 18:10:01 +00:00
James Hilton-Balfe
3f377e3bfd
Remove the poetry.lock (#338) 2022-02-15 15:37:47 +00:00
Eitan Mosenkis
eeddc844a5
Bump Jinja2 to 3.0.3. (#330) 2022-02-01 08:32:25 +00: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
dependabot[bot]
671c0ff4ac
Bump urllib3 from 1.26.4 to 1.26.5 (#288)
Bumps [urllib3](https://github.com/urllib3/urllib3) from 1.26.4 to 1.26.5.
- [Release notes](https://github.com/urllib3/urllib3/releases)
- [Changelog](https://github.com/urllib3/urllib3/blob/main/CHANGES.rst)
- [Commits](https://github.com/urllib3/urllib3/compare/1.26.4...1.26.5)

---
updated-dependencies:
- dependency-name: urllib3
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-11 18:31:26 -08:00
dependabot[bot]
9cecc8c3ff
Bump babel from 2.9.0 to 2.9.1 (#289)
Bumps [babel](https://github.com/python-babel/babel) from 2.9.0 to 2.9.1.
- [Release notes](https://github.com/python-babel/babel/releases)
- [Changelog](https://github.com/python-babel/babel/blob/master/CHANGES)
- [Commits](https://github.com/python-babel/babel/compare/v2.9.0...v2.9.1)

---
updated-dependencies:
- dependency-name: babel
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-11 18:30:43 -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
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
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
nat
59f5f88c0d
Rebuild poetry.lock to fix CI (#202) 2021-01-25 20:28:30 +01:00
Arun Babu Neelicattu
a8a082e4e7
Update dependencies and add ci checks for python 3.9 (#173)
* Update locked dependencies to fix grpcio compile issue with python 3.9
* ci: add python 3.9
2020-11-24 19:28:28 +01: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
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
0d9387abec Remove stringcase dependency 2020-07-01 12:43:12 +02:00
Nat Noordanus
75a4c230da Add optional deps to dev-deps
So contributors dont have to remember to run poetry install with `-E compiler`
2020-06-22 19:35:23 +02:00
Nat Noordanus
8edec81b11 Switch from pipenv to poetry
- dropped dev dependency on rope, isort & flake
- poetry doesn't support dev scripts like pipenv, so create a makefile instead
- Add pytest-cov
- Use tox for testing multiple python versions in CI
- Update README

Update ci workflow
2020-06-12 21:13:55 +02:00