Skip to content

Commit 5b1ed7a

Browse files
Recompile compiler lib (#132)
* Recompile compiler lib * Update compiler lib * Fix typechecking issue * Update documentation
1 parent 754f34a commit 5b1ed7a

12 files changed

Lines changed: 1073 additions & 170 deletions

File tree

betterproto2/docs/development.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,7 @@ This page targets the betterproto maintainers.
55
## Recompiling the lib proto files
66

77
After some updates in the compiler, it might be useful to recompile the standard Google proto files used by the
8-
compiler. As the proto files are distributed with `protoc`, their path might depend on your installation.
9-
10-
```bash
11-
mkdir lib
12-
protoc \
13-
--python_betterproto2_out=lib \
14-
-I /usr/include/ \
15-
/usr/include/google/protobuf/*.proto
16-
```
8+
compiler. The output of the `compiler_lib` test should be used.
179

1810
!!! warning
1911
These proto files are written with the `proto2` syntax, which is not supported by betterproto. For the compiler to

betterproto2_compiler/src/betterproto2_compiler/known_types/duration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ def delta_to_json(delta: datetime.timedelta) -> str:
3030

3131
# TODO typing
3232
@classmethod
33-
def from_dict(cls, value):
33+
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
3434
if isinstance(value, str):
3535
if not re.match(r"^\d+(\.\d+)?s$", value):
3636
raise ValueError(f"Invalid duration string: {value}")
3737

3838
seconds = float(value[:-1])
3939
return Duration(seconds=int(seconds), nanos=int((seconds - int(seconds)) * 1e9))
4040

41-
return super().from_dict(value)
41+
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)
4242

4343
# TODO typing
4444
def to_dict(

betterproto2_compiler/src/betterproto2_compiler/known_types/timestamp.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def timestamp_to_json(dt: datetime.datetime) -> str:
5555

5656
# TODO typing
5757
@classmethod
58-
def from_dict(cls, value):
58+
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
5959
if isinstance(value, str):
6060
dt = dateutil.parser.isoparse(value)
6161
dt = dt.astimezone(datetime.timezone.utc)
6262
return Timestamp.from_datetime(dt)
6363

64-
return super().from_dict(value)
64+
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)
6565

6666
# TODO typing
6767
def to_dict(

betterproto2_compiler/src/betterproto2_compiler/lib/__init__.py

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

0 commit comments

Comments
 (0)