Skip to content
This repository was archived by the owner on Feb 23, 2026. It is now read-only.

Commit 117907a

Browse files
committed
lint
1 parent ac98abe commit 117907a

3 files changed

Lines changed: 36 additions & 11 deletions

File tree

proto/message.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -419,15 +419,26 @@ def to_json(
419419

420420
# For backwards compatibility of this breaking change in protobuf 5.x which is specific to proto2
421421
# https://github.com/protocolbuffers/protobuf/commit/26995798757fbfef5cf6648610848e389db1fecf
422-
if always_print_fields_with_no_presence is not None and including_default_value_fields is not None and always_print_fields_with_no_presence != including_default_value_fields:
423-
raise ValueError("Arguments `always_print_fields_with_no_presence` and `including_default_value_fields` must match")
422+
if (
423+
always_print_fields_with_no_presence is not None
424+
and including_default_value_fields is not None
425+
and always_print_fields_with_no_presence != including_default_value_fields
426+
):
427+
raise ValueError(
428+
"Arguments `always_print_fields_with_no_presence` and `including_default_value_fields` must match"
429+
)
424430

425431
# By default, fields with no presense will be included in the results
426432
# when both `always_print_fields_with_no_presence` and `including_default_value_fields` are not set
427-
if always_print_fields_with_no_presence is None and including_default_value_fields is None:
433+
if (
434+
always_print_fields_with_no_presence is None
435+
and including_default_value_fields is None
436+
):
428437
print_fields = True
429438
else:
430-
print_fields = always_print_fields_with_no_presence or including_default_value_fields
439+
print_fields = (
440+
always_print_fields_with_no_presence or including_default_value_fields
441+
)
431442

432443
if PROTOBUF_VERSION[0] in ("3", "4"):
433444
return MessageToJson(
@@ -513,15 +524,26 @@ def to_dict(
513524

514525
# For backwards compatibility of this breaking change in protobuf 5.x which is specific to proto2
515526
# https://github.com/protocolbuffers/protobuf/commit/26995798757fbfef5cf6648610848e389db1fecf
516-
if always_print_fields_with_no_presence is not None and including_default_value_fields is not None and always_print_fields_with_no_presence != including_default_value_fields:
517-
raise ValueError("Arguments `always_print_fields_with_no_presence` and `including_default_value_fields` must match")
527+
if (
528+
always_print_fields_with_no_presence is not None
529+
and including_default_value_fields is not None
530+
and always_print_fields_with_no_presence != including_default_value_fields
531+
):
532+
raise ValueError(
533+
"Arguments `always_print_fields_with_no_presence` and `including_default_value_fields` must match"
534+
)
518535

519536
# By default, fields with no presense will be included in the results
520537
# when both `always_print_fields_with_no_presence` and `including_default_value_fields` are not set
521-
if always_print_fields_with_no_presence is None and including_default_value_fields is None:
538+
if (
539+
always_print_fields_with_no_presence is None
540+
and including_default_value_fields is None
541+
):
522542
print_fields = True
523543
else:
524-
print_fields = always_print_fields_with_no_presence or including_default_value_fields
544+
print_fields = (
545+
always_print_fields_with_no_presence or including_default_value_fields
546+
)
525547

526548
if PROTOBUF_VERSION[0] in ("3", "4"):
527549
return MessageToDict(

tests/conftest.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ def pytest_runtest_setup(item):
4141

4242
item._mocks.append(
4343
mock.patch(
44-
"google._upb._message.default_pool"
45-
if has_upb()
46-
else "google.protobuf.pyext._message.default_pool",
44+
(
45+
"google._upb._message.default_pool"
46+
if has_upb()
47+
else "google.protobuf.pyext._message.default_pool"
48+
),
4749
pool,
4850
)
4951
)

tests/test_fields_mitigate_collision.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import proto
1616
import pytest
1717

18+
1819
# Underscores may be appended to field names
1920
# that collide with python or proto-plus keywords.
2021
# In case a key only exists with a `_` suffix, coerce the key

0 commit comments

Comments
 (0)