You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
The default_factory for subgroups will not set the default metavar in FieldWrapper.
To Reproduce
# test_subgroups_default_factory.pyfromtypingimportUnionfromdataclassesimportdataclass, is_dataclass, MISSINGimportpytestfromsimple_parsingimportsubgroupsfrom .testutilsimportTestSetup@dataclassclassFoo:
a: int=1b: int=2@dataclassclassBar:
c: int=1d: int=2@dataclassclassBob(TestSetup):
thing: Union[Foo, Bar] =subgroups({"foo_thing": Foo, "bar_thing": Bar}, default_factory=lambda: Bar(d=3))
# the original design will only work when using the "default" argument.# thing: Union[Foo, Bar] = subgroups({"foo_thing": Foo, "bar_thing": Bar}, default=Bar(d=3)) deftest_default_factory_subgroups():
assert'--thing.c'inBob.get_help_text('--help')
Expected behavior
Test passed
Actual behavior
Failed
AssertionError: assert '--thing.c' in ''
Desktop (please complete the following information):
Version: 0.0.21.post1
Python version: Python 3.9
Additional context
The below default_value function check both field.default and field.default_factory.
# utilis.pydefdefault_value(field: dataclasses.Field) ->T|_MISSING_TYPE:
"""Returns the default value of a field in a dataclass, if available. When not available, returns `dataclasses.MISSING`. Args: field (dataclasses.Field): The dataclasses.Field to get the default value of. Returns: Union[T, _MISSING_TYPE]: The default value for that field, if present, or None otherwise. """iffield.defaultisnotdataclasses.MISSING:
returnfield.defaulteliffield.default_factoryisnotdataclasses.MISSING: # type: ignoreconstructor=field.default_factory# type: ignorereturnconstructor()
else:
returndataclasses.MISSING
However, the subgroups give the default value of "default" "None" instead of MISSING.
Describe the bug
The default_factory for subgroups will not set the default metavar in FieldWrapper.
To Reproduce
Expected behavior
Test passed
Actual behavior
Failed
AssertionError: assert '--thing.c' in ''
Desktop (please complete the following information):
Additional context
The below
default_value
function check both field.default and field.default_factory.However, the subgroups give the default value of "default" "None" instead of MISSING.
The text was updated successfully, but these errors were encountered: