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

argparse: space in an incorrect argument adds it to nargs="*", instead of raising an error #114429

Closed
abcydybcy opened this issue Jan 22, 2024 · 1 comment
Labels
type-bug An unexpected behavior, bug, or error

Comments

@abcydybcy
Copy link

abcydybcy commented Jan 22, 2024

Bug report

Bug description:

Code to recreate:

import argparse
parser = argparse.ArgumentParser()
parser.add_argument("args", nargs="*")
print(parser.parse_args())

Current behaviour:
If the wrong argument contains a space, it is added to the catch-all arguments:

> python bug.py --wrong-arg="foo bar"
Namespace(args=['--wrong-arg=foo bar'])

But if it doesn't contain a space, expected behaviour happens:

> python bug.py --wrong-arg="foobar" 
usage: bug.py [-h] [args ...]
bug.py: error: unrecognized arguments: --wrong-arg=foobar

Expected behaviour:
Calling this program as bug.py --wrong-argument="foo bar" prints an error message:

usage: bug.py [-h] [--name NAME] [args ...]
bug.py: error: unrecognized arguments: --wrong-arg=foo bar.

CPython versions tested on:

3.11

Operating systems tested on:

No response

@abcydybcy abcydybcy added the type-bug An unexpected behavior, bug, or error label Jan 22, 2024
@hugovk
Copy link
Member

hugovk commented Jan 22, 2024

Thanks for the report, this looks like a duplicate of #66623.

@hugovk hugovk closed this as not planned Won't fix, can't repro, duplicate, stale Jan 22, 2024
@abcydybcy abcydybcy changed the title argparse: space in incorrect argument adds it to catch-all argument, instead of raising an error argparse: space in an incorrect argument adds it to nargs="*", instead of raising an error Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants