Skip to content

Commit 34f6043

Browse files
committed
Fix non-init fields being passed to DC's __init__
Signed-off-by: Fabrice Normandin <[email protected]>
1 parent f992ffb commit 34f6043

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

simple_parsing/parsing.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -948,11 +948,14 @@ def _fill_constructor_arguments_with_fields(
948948
f for f in dataclasses.fields(dc_wrapper.dataclass) if not f.init
949949
]:
950950
field_dest = dc_wrapper.dest + "." + non_init_field.name
951-
# We fetch the constructor arguments for the containing dataclass and check that it
951+
# Fetch the constructor arguments for the containing dataclass and check that it
952952
# doesn't have a value set.
953-
dc_constructor_args = constructor_arguments
954-
for dest_part in dc_wrapper.dest.split("."):
955-
dc_constructor_args = dc_constructor_args[dest_part]
953+
# NOTE: The `constructor_arguments` dict is FLAT here, so each dataclass has its
954+
# own corresponding arguments at their destination, like `"a.b": {}`.
955+
dc_constructor_args = constructor_arguments[dc_wrapper.dest]
956+
957+
# for dest_part in dc_wrapper.dest.split("."):
958+
# dc_constructor_args = dc_constructor_args[dest_part]
956959
if non_init_field.name in dc_constructor_args:
957960
logger.warning(
958961
f"Field {field_dest} is a field with init=False, but a value is "

0 commit comments

Comments
 (0)