Skip to content

Commit 6592d4d

Browse files
authored
Merge branch 'master' into remove-enum-prefix
2 parents 7b6f03d + 671c0ff commit 6592d4d

28 files changed

+550
-139
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
strategy:
1616
matrix:
1717
os: [Ubuntu, MacOS, Windows]
18-
python-version: [3.6, 3.7, 3.8, 3.9]
18+
python-version: ['3.6.7', 3.7, 3.8, 3.9]
1919
exclude:
2020
- os: Windows
2121
python-version: 3.6

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
- Versions suffixed with `b*` are in `beta` and can be installed with `pip install --pre betterproto`.
99

10+
## [2.0.0b3] - 2021-04-07
11+
12+
- Generate grpclib service stubs [#170](https://github.com/danielgtaylor/python-betterproto/pull/170)
13+
- Add \_\_version\_\_ attribute to package [#134](https://github.com/danielgtaylor/python-betterproto/pull/134)
14+
- Use betterproto generated messages in the plugin [#161](https://github.com/danielgtaylor/python-betterproto/pull/161)
15+
- Sort the list of sources in generated file headers [#164](https://github.com/danielgtaylor/python-betterproto/pull/164)
16+
- Micro-optimization: use tuples instead of lists for conditions [#228](https://github.com/danielgtaylor/python-betterproto/pull/228)
17+
- Improve datestring parsing [#213](https://github.com/danielgtaylor/python-betterproto/pull/213)
18+
19+
- Fix serialization of repeated fields with empty messages [#180](https://github.com/danielgtaylor/python-betterproto/pull/180)
20+
- Fix compilation of fields named 'bytes' or 'str' [#226](https://github.com/danielgtaylor/python-betterproto/pull/226)
21+
- Fix json serialization of infinite and nan floats/doubles [#215](https://github.com/danielgtaylor/python-betterproto/pull/215)
22+
- Fix template bug resulting in empty \_\_post_init\_\_ methods [#162](https://github.com/danielgtaylor/python-betterproto/pull/162)
23+
- Fix serialization of zero-value messages in a oneof group [#176](https://github.com/danielgtaylor/python-betterproto/pull/176)
24+
- Fix missing typing and datetime imports [#183](https://github.com/danielgtaylor/python-betterproto/pull/183)
25+
- Fix code generation for empty services [#222](https://github.com/danielgtaylor/python-betterproto/pull/222)
26+
- Fix Message.to_dict and from_dict handling of repeated timestamps and durations [#211](https://github.com/danielgtaylor/python-betterproto/pull/211)
27+
- Fix incorrect routes in generated client when service is not in a package [#177](https://github.com/danielgtaylor/python-betterproto/pull/177)
28+
1029
## [2.0.0b2] - 2020-11-24
1130

1231
- Add support for deprecated message and fields [#126](https://github.com/danielgtaylor/python-betterproto/pull/126)

README.md

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,12 @@ service Echo {
160160
}
161161
```
162162

163+
Generate echo proto file:
164+
165+
```
166+
python -m grpc_tools.protoc -I . --python_betterproto_out=. echo.proto
167+
```
168+
163169
A client can be implemented as follows:
164170
```python
165171
import asyncio
@@ -199,28 +205,29 @@ To use them, simply subclass the base class in the generated files and override
199205
service methods:
200206

201207
```python
202-
from echo import EchoBase
208+
import asyncio
209+
from echo import EchoBase, EchoResponse, EchoStreamResponse
203210
from grpclib.server import Server
204211
from typing import AsyncIterator
205212

206213

207214
class EchoService(EchoBase):
208215
async def echo(self, value: str, extra_times: int) -> "EchoResponse":
209-
return value
216+
return EchoResponse([value for _ in range(extra_times)])
210217

211-
async def echo_stream(
212-
self, value: str, extra_times: int
213-
) -> AsyncIterator["EchoStreamResponse"]:
218+
async def echo_stream(self, value: str, extra_times: int) -> AsyncIterator["EchoStreamResponse"]:
214219
for _ in range(extra_times):
215-
yield value
220+
yield EchoStreamResponse(value)
216221

217222

218-
async def start_server():
219-
HOST = "127.0.0.1"
220-
PORT = 1337
223+
async def main():
221224
server = Server([EchoService()])
222-
await server.start(HOST, PORT)
223-
await server.serve_forever()
225+
await server.start("127.0.0.1", 50051)
226+
await server.wait_closed()
227+
228+
if __name__ == '__main__':
229+
loop = asyncio.get_event_loop()
230+
loop.run_until_complete(main())
224231
```
225232

226233
### JSON

benchmarks/benchmarks.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import betterproto
22
from dataclasses import dataclass
33

4+
from typing import List
5+
46

57
@dataclass
68
class TestMessage(betterproto.Message):
@@ -9,13 +11,60 @@ class TestMessage(betterproto.Message):
911
baz: float = betterproto.float_field(2)
1012

1113

14+
@dataclass
15+
class TestNestedChildMessage(betterproto.Message):
16+
str_key: str = betterproto.string_field(0)
17+
bytes_key: bytes = betterproto.bytes_field(1)
18+
bool_key: bool = betterproto.bool_field(2)
19+
float_key: float = betterproto.float_field(3)
20+
int_key: int = betterproto.uint64_field(4)
21+
22+
23+
@dataclass
24+
class TestNestedMessage(betterproto.Message):
25+
foo: TestNestedChildMessage = betterproto.message_field(0)
26+
bar: TestNestedChildMessage = betterproto.message_field(1)
27+
baz: TestNestedChildMessage = betterproto.message_field(2)
28+
29+
30+
@dataclass
31+
class TestRepeatedMessage(betterproto.Message):
32+
foo_repeat: List[str] = betterproto.string_field(0)
33+
bar_repeat: List[int] = betterproto.int64_field(1)
34+
baz_repeat: List[bool] = betterproto.bool_field(2)
35+
36+
1237
class BenchMessage:
1338
"""Test creation and usage a proto message."""
1439

1540
def setup(self):
1641
self.cls = TestMessage
1742
self.instance = TestMessage()
1843
self.instance_filled = TestMessage(0, "test", 0.0)
44+
self.instance_filled_bytes = bytes(self.instance_filled)
45+
self.instance_filled_nested = TestNestedMessage(
46+
TestNestedChildMessage("foo", bytearray(b"test1"), True, 0.1234, 500),
47+
TestNestedChildMessage("bar", bytearray(b"test2"), True, 3.1415, -302),
48+
TestNestedChildMessage("baz", bytearray(b"test3"), False, 1e5, 300),
49+
)
50+
self.instance_filled_nested_bytes = bytes(self.instance_filled_nested)
51+
self.instance_filled_repeated = TestRepeatedMessage(
52+
[
53+
"test1",
54+
"test2",
55+
"test3",
56+
"test4",
57+
"test5",
58+
"test6",
59+
"test7",
60+
"test8",
61+
"test9",
62+
"test10",
63+
],
64+
[2, -100, 0, 500000, 600, -425678, 1000000000, -300, 1, -694214214466],
65+
[True, False, False, False, True, True, False, True, False, False],
66+
)
67+
self.instance_filled_repeated_bytes = bytes(self.instance_filled_repeated)
1968

2069
def time_overhead(self):
2170
"""Overhead in class definition."""
@@ -50,6 +99,26 @@ def time_serialize(self):
5099
"""Time serializing a message to wire."""
51100
bytes(self.instance_filled)
52101

102+
def time_deserialize(self):
103+
"""Time deserialize a message."""
104+
TestMessage().parse(self.instance_filled_bytes)
105+
106+
def time_serialize_nested(self):
107+
"""Time serializing a nested message to wire."""
108+
bytes(self.instance_filled_nested)
109+
110+
def time_deserialize_nested(self):
111+
"""Time deserialize a nested message."""
112+
TestNestedMessage().parse(self.instance_filled_nested_bytes)
113+
114+
def time_serialize_repeated(self):
115+
"""Time serializing a repeated message to wire."""
116+
bytes(self.instance_filled_repeated)
117+
118+
def time_deserialize_repeated(self):
119+
"""Time deserialize a repeated message."""
120+
TestRepeatedMessage().parse(self.instance_filled_repeated_bytes)
121+
53122

54123
class MemSuite:
55124
def setup(self):

poetry.lock

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

0 commit comments

Comments
 (0)