413 Commits

Author SHA1 Message Date
James Hilton-Balfe
f96f51650c
fix: 3.10 style imports not resolving correctly (#594) 2024-08-14 08:01:31 +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
8b59234856
Handle typing collisions and add validation to a files module for overlaping declarations (#582)
* Fix 'typing' import collisions.

* Fix formatting.

* Fix self-test issues.

* Validation for modules, different typing configurations

* add readme

* make warning

* fix format

---------

Co-authored-by: Scott Hendricks <scott.hendricks@confluent.io>
2024-07-20 00:02:09 +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
atomicmac
df1ba911b7
Add betterproto.Enum __copy__ and __deepcopy__ implementations (#566)
* Add betterproto.Enum __copy__ and __deepcopy__ implementations

betterproto.Enum is missing __copy__ and __deepcopy__ implementations, which were recently added to enum.Enum, see https://github.com/python/cpython/issues/106602
This fixes the bug where betterproto messages with Enums nested within cannot be copied via copy.deepcopy.

* Type hint on Enum.__copy__

Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>

* Type hint on Enum.__deepcopy__

Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>

---------

Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2024-03-29 14:08:02 +00:00
Arun Sathiya
126b256b4c
ci: Use GITHUB_OUTPUT envvar instead of set-output command (#553)
* ci: Use GITHUB_OUTPUT envvar instead of set-output command

* Quote envvar to match documentation
2024-03-24 00:56:48 +00:00
atomicmac
e98c47861d
refactor: use is instead of == (#560)
PLACEHOLDER is a specific instance of an object, the test here should be "is not" instead of "!="
I am experimenting with adding ndarray support, and the equality test here causes problems.
2024-03-23 21:43:56 +00:00
Micael Jarniac
dbd31929d3
Add one-of match example to README (#558)
Removed the parts of the example that showed accessing an unset value, as it now raises an `AttributeError`, and added an example of the `match` way of accessing the attributes.

Related to #510 and #358.
2024-03-19 21:54:32 +00:00
William Woodruff
5666393f9d
betterproto: support Struct and Value (#551)
* betterproto: support `Struct` and `Value`

Signed-off-by: William Woodruff <william@trailofbits.com>

* betterproto: handle struct in to_dict as well

Signed-off-by: William Woodruff <william@trailofbits.com>

* tests: add Struct roundtrip tests

Signed-off-by: William Woodruff <william@trailofbits.com>

* specialize from_dict and to_dict on Struct

...rather than special-casing in the Message ABC.

Signed-off-by: William Woodruff <william@trailofbits.com>

* betterproto: `poe format`

Signed-off-by: William Woodruff <william@trailofbits.com>

* Update src/betterproto/__init__.py

Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>

* remove future annotations

Signed-off-by: William Woodruff <william@trailofbits.com>

* replace type[...] with typing.T

Signed-off-by: William Woodruff <william@trailofbits.com>

* quote instead

Signed-off-by: William Woodruff <william@trailofbits.com>

---------

Signed-off-by: William Woodruff <william@trailofbits.com>
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2024-01-02 20:16:15 +00:00
Christian Clauss
ce5093eec0
Upgrade actions to 3.12 (#550) 2024-01-02 14:49:16 +00:00
John Collins
b8a091ae70
Turn off doc-string line wrapping (#532) 2023-12-16 13:36:53 +00: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
James Hilton-Balfe
bd7de203e1
Remove Enum prefixes (#187)
Co-authored-by: nat <n@natn.me>
Co-authored-by: Tim Schmidt <w4rum@users.noreply.github.com>
Co-authored-by: Arun Babu Neelicattu <arun.neelicattu@gmail.com>
2023-10-25 22:35:16 +01:00
Marek Pikuła
d9b7608980
Support Message.from_dict() as a class and an instance method (#476)
* Make Message.from_dict() a class method

Signed-off-by: Marek Pikuła <marek.pikula@embevity.com>

* Sync 1/2 of review comments

* Sync other half

* Update .pre-commit-config.yaml

* Update __init__.py

* Update utils.py

* Update src/betterproto/__init__.py

* Update .pre-commit-config.yaml

* Update __init__.py

* Update utils.py

* Fix CI again

* Fix failing formatting

---------

Signed-off-by: Marek Pikuła <marek.pikula@embevity.com>
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2023-10-25 22:20:23 +01:00
Lukas Bindreiter
02aa4e88b7
Fix _Timestamp edge cases (#534)
* Add failing test cases for timestamp conversion

* Fix timestamp to datetime conversion

* Fix formatting

* Move timestamp tests outside of inputs folder

---------

Co-authored-by: Lukas Bindreiter <lukas.bindreiter@tilebox.io>
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2023-10-18 00:41:09 +01:00
James Hilton-Balfe
1dd001b6d3
Add CodeQL scanning (#418) 2023-10-18 09:55:28 +11:00
Sebastian Pietras
e309513131
Fix _stream_unary not working with empty iterables (#422)
* Fixed `do_many_things` method in `ThingService`
* Added test for empty iterables
* Fixed `_stream_unary` not sending request first
2023-10-18 09:54:23 +11:00
Joshua Leivers
24db53290e
Fix Tox to use Poetry hermetically (#531) 2023-10-17 14:56:58 +01:00
James Hilton-Balfe
2bcb05a905
Tests for #523 (#538) 2023-10-16 22:33:42 +11: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
Joshua Leivers
4f18ed1325
Add support for streaming delimited messages (#529)
* Add support for streaming delimited messages

This allows developers to easily dump and load multiple messages
from a stream in a way that is compatible with official
protobuf implementations (such as Java's
`MessageLite#writeDelimitedTo(...)`).

* Add Java compatibility tests for streaming

These tests stream data such as messages to output files, have a
Java binary read them and then write them back using the
`protobuf-java` functions, and then read them back in on the Python
side to check that the returned data is as expected. This checks
that the official Java implementation (and so any other matching
implementations) can properly parse outputs from Betterproto, and
vice-versa, ensuring compatibility in these functions between the
two.

* Replace `xxxxableBuffer` with `SupportsXxxx`
2023-10-16 21:59:33 +11:00
James Hilton-Balfe
6b36b9ba9f
Add issue templates (#166) 2023-10-16 14:23:14 +11:00
Girts
61d192e207
test for issue #305, marked with xfail (#306) 2023-10-16 14:18:24 +11:00
Erik Friese
8b5dd6c1f8
Dont set group for optional fields (#528)
Fixes #523
2023-10-16 13:43:42 +11:00
Micael Jarniac
3514991133
Rich support (#508)
Closes #507

https://rich.readthedocs.io/en/latest/pretty.html#rich-repr-protocol
2023-10-16 13:36:26 +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
Joshua Leivers
8659c51123
Add message streaming support (#518) 2023-08-29 14:26:25 +01:00
Andrew
4cdf1bb9e0
Fix Message equality comparison (#513) 2023-07-29 12:06:56 +01: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
Ollie
182aedaec4
Handle empty value objects properly (#481)
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2023-06-24 20:19:13 +01:00
konstantin
a7532bbadc
Add Python 3.11 to CI Runs (#445)
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2023-06-24 19:49:34 +01:00
Alexander Khabarov
73d1fa3d5b
Upgrade grpcio-tools and protobuf (#498) 2023-06-24 19:39:11 +01:00
Sriansh Raj Pradhan
c00bc96db7
Create LICENSE.md (#502) 2023-06-16 19:19:51 +01:00
Nick DeRobertis
fcbd8a3759
Fix pydict serialization for optional fields (#495) 2023-05-28 17:47:52 +01:00
pi-slh
aad7d2ad76
Replace pkg_resources with importlib (#462) 2023-05-25 11:12:15 +01:00
Jinyu Liu
2b41383745
Fix dict encoding for timezone aware datetimes (#468)
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
2023-04-13 23:34:19 +01:00
Marek Pikuła
b0b6cd24ad
Fix pydantic_dataclasses reference in README (#474) 2023-04-13 21:56:38 +01:00
James Hilton-Balfe
e7f07fa2a1
Update __init__.py (#451) 2023-03-08 08:20:56 +00:00
Samuel Yvon
2fa0be2141
Fix for #459 (pydantic code gen only) (#460) 2023-02-21 19:41:32 +00: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
Wouter Horré
0adcc9020c
Pythonize input_type name in py_input_message (#436)
Co-authored-by: konstantin <konstantin.klein@hochfrequenz.de>
Co-authored-by: James Hilton-Balfe <gobot1234yt@gmail.com>
Fixes https://github.com/danielgtaylor/python-betterproto/issues/427
Fixes https://github.com/danielgtaylor/python-betterproto/issues/438
2022-12-02 22:18:48 +00:00
sterliakov
bfc0fac754
Enforce serialize_empty for repeated fields (#417) 2022-08-31 18:59:12 +01:00
Antonín Říha
8fbf4476a8
Fix typechecker compatiblity checks in server streaming methods (#413) 2022-08-31 00:05:29 +01:00
Samuel Yvon
591ec5efb3
Pull down the include_default_values argument to to_json (#405) 2022-08-08 14:26:28 +01:00