Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 1 addition & 9 deletions betterproto2/docs/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,7 @@ This page targets the betterproto maintainers.
## Recompiling the lib proto files

After some updates in the compiler, it might be useful to recompile the standard Google proto files used by the
compiler. As the proto files are distributed with `protoc`, their path might depend on your installation.

```bash
mkdir lib
protoc \
--python_betterproto2_out=lib \
-I /usr/include/ \
/usr/include/google/protobuf/*.proto
```
compiler. The output of the `compiler_lib` test should be used.

!!! warning
These proto files are written with the `proto2` syntax, which is not supported by betterproto. For the compiler to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ def delta_to_json(delta: datetime.timedelta) -> str:

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

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

return super().from_dict(value)
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)

# TODO typing
def to_dict(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def timestamp_to_json(dt: datetime.datetime) -> str:

# TODO typing
@classmethod
def from_dict(cls, value):
def from_dict(cls, value, *, ignore_unknown_fields: bool = False):
if isinstance(value, str):
dt = dateutil.parser.isoparse(value)
dt = dt.astimezone(datetime.timezone.utc)
return Timestamp.from_datetime(dt)

return super().from_dict(value)
return super().from_dict(value, ignore_unknown_fields=ignore_unknown_fields)

# TODO typing
def to_dict(
Expand Down
12 changes: 12 additions & 0 deletions betterproto2_compiler/src/betterproto2_compiler/lib/__init__.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading