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
When argparse creates a new simple_parsing.ArgumentParser in the call to parser.add_subparsers it doesn't pass the original kwargs (obviously), so the global class attributes on FieldWrapper like add_dash_variants get overwritten with the defaults.
Your refactor may address this, but in case you weren't aware I thought I'd raise the issue. Those globals seem not ideal.
Here's a workaround:
importinspectimportpathlibFIRST_KWARGS=NoneclassArgumentParser(simple_parsing.ArgumentParser):
def__init__(self, *args, **kwargs):
globalFIRST_KWARGSifFIRST_KWARGSisNone:
FIRST_KWARGS=kwargs# only enforce FIRST_KWARGS when called by argparsecaller=inspect.stack()[1]
caller_path=pathlib.Path(caller.filename)
ifcaller_path.match("*lib/**/argparse.py"):
super().__init__(*args, **FIRST_KWARGS)
else:
super().__init__(*args, **kwargs)
To Reproduce
Use subparsers with non-default kwargs on the top level parser, e.g., add_dash_variants.
Expected behavior
Subparsers obey the kwargs used by the parent.
Actual behavior
Subparsers use default kwargs.
Desktop (please complete the following information):
Version latest pip installable
Python version: 3,11.8
The text was updated successfully, but these errors were encountered:
Totally agree. I definitely need to remove those global vars. One idea could be to preserve the kwargs on the ArgumentParser so that parser.add_subparsers transfers them. I'll have to try that out.
Describe the bug
When
argparse
creates a newsimple_parsing.ArgumentParser
in the call toparser.add_subparsers
it doesn't pass the original kwargs (obviously), so the global class attributes onFieldWrapper
likeadd_dash_variants
get overwritten with the defaults.Your refactor may address this, but in case you weren't aware I thought I'd raise the issue. Those globals seem not ideal.
Here's a workaround:
To Reproduce
Use subparsers with non-default kwargs on the top level parser, e.g.,
add_dash_variants
.Expected behavior
Subparsers obey the kwargs used by the parent.
Actual behavior
Subparsers use default kwargs.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: