Skip to content
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

Is argparse.SUPPRESS needed for anything in def create_cli_parser? #1115

Open
PawelLipski opened this issue Nov 28, 2023 · 1 comment
Open
Labels
cli Relates to command-line interface code quality Quality of the code nees improving good first issue Good for newcomers

Comments

@PawelLipski
Copy link
Collaborator

PawelLipski commented Nov 28, 2023

Maybe it at least affects error message in case of invalid CLI options?

Either put a comment explaining why it's needed, or remove if not.

@PawelLipski PawelLipski added good first issue Good for newcomers code quality Quality of the code nees improving cli Relates to command-line interface labels Nov 28, 2023
@PawelLipski
Copy link
Collaborator Author

PawelLipski commented Sep 24, 2024

>>> import argparse
>>> parser = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
>>> parser.add_argument('--foo')
_StoreAction(option_strings=['--foo'], dest='foo', nargs=None, const=None, default='==SUPPRESS==', type=None, choices=None, required=False, help=None, metavar=None)
>>> parser.add_argument('bar', nargs='?')
_StoreAction(option_strings=[], dest='bar', nargs='?', const=None, default='==SUPPRESS==', type=None, choices=None, required=False, help=None, metavar=None)
>>> parser.parse_args(['--foo', '1', 'BAR'])
Namespace(foo='1', bar='BAR')
>>> parser.parse_args([])    ### HERE
Namespace()
>>> parser2 = argparse.ArgumentParser(argument_default=argparse.SUPPRESS)
>>> parser2 = argparse.ArgumentParser()
>>> parser2.add_argument('--foo')
_StoreAction(option_strings=['--foo'], dest='foo', nargs=None, const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)
>>> parser2.add_argument('bar', nargs='?')
_StoreAction(option_strings=[], dest='bar', nargs='?', const=None, default=None, type=None, choices=None, required=False, help=None, metavar=None)
>>> parser2.parse_args(['--foo', '1', 'BAR'])
Namespace(foo='1', bar='BAR')
>>> parser2.parse_args([])   ### vs HERE
Namespace(foo=None, bar=None)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cli Relates to command-line interface code quality Quality of the code nees improving good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

1 participant