Skip to content

Fix to_(py)?dict bool fields #494

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
11 changes: 3 additions & 8 deletions src/betterproto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1344,6 +1344,8 @@ def to_pydict(
defaults = self._betterproto.default_gen
for field_name, meta in self._betterproto.meta_by_field_name.items():
field_is_repeated = defaults[field_name] is list
if self.__raw_get(field_name) is PLACEHOLDER and not include_default_values:
continue
value = getattr(self, field_name)
cased_name = casing(field_name).rstrip("_") # type: ignore
if meta.proto_type == TYPE_MESSAGE:
Expand Down Expand Up @@ -1388,13 +1390,7 @@ def to_pydict(

if value or include_default_values:
output[cased_name] = value
elif (
value != self._get_field_default(field_name)
or include_default_values
or self._include_default_value_for_oneof(
field_name=field_name, meta=meta
)
):
else:
output[cased_name] = value
return output

Expand Down Expand Up @@ -1476,7 +1472,6 @@ def _validate_field_groups(cls, values):
field_name_to_meta = cls._betterproto_meta.meta_by_field_name # type: ignore

for group, field_set in group_to_one_ofs.items():

if len(field_set) == 1:
(field,) = field_set
field_name = field.name
Expand Down
1 change: 0 additions & 1 deletion src/betterproto/grpc/grpclib_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ async def _call_rpc_handler_server_stream(
stream: grpclib.server.Stream,
request: Any,
) -> None:

response_iter = handler(request)
# check if response is actually an AsyncIterator
# this might be false if the method just returns without
Expand Down
1 change: 0 additions & 1 deletion src/betterproto/plugin/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@


def outputfile_compiler(output_file: OutputTemplate) -> str:

templates_folder = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "templates")
)
Expand Down
1 change: 0 additions & 1 deletion src/betterproto/plugin/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ def _make_one_of_field_compiler(
proto_obj: "FieldDescriptorProto",
path: List[int],
) -> FieldCompiler:

pydantic = output_package.pydantic_dataclasses
Cls = PydanticOneOfFieldCompiler if pydantic else OneOfFieldCompiler
return Cls(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@


def test_oneof_serializes_similar_to_google_oneof():

tests = [
(Test(string="abc"), ReferenceTest(string="abc")),
(Test(integer=2), ReferenceTest(integer=2)),
Expand All @@ -30,7 +29,6 @@ def test_oneof_serializes_similar_to_google_oneof():


def test_bytes_are_the_same_for_oneof():

message = Test(string="")
message_reference = ReferenceTest(string="")

Expand Down