Skip to content

argparse does not handle hyphens in positional arguments #100411

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

Closed
Gregofi opened this issue Dec 21, 2022 · 3 comments
Closed

argparse does not handle hyphens in positional arguments #100411

Gregofi opened this issue Dec 21, 2022 · 3 comments
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement

Comments

@Gregofi
Copy link

Gregofi commented Dec 21, 2022

Bug report

argparse doesn't convert hyphens to underscores in positional arguments

import argparse

parser = argparse.ArgumentParser()

parser.add_argument('hyp-hens1')
parser.add_argument('--hyp-hens2')

args = parser.parse_args()

print(args.hyp_hens2)
print(args.hyp_hens1)

Should run fine when first arg is provided, instead

Traceback (most recent call last):
  File "/app/output.s", line 11, in <module>
    print(args.hyp_hens1)
          ^^^^^^^^^^^^^^
AttributeError: 'Namespace' object has no attribute 'hyp_hens1'. Did you mean: 'hyp-hens1'?

Your environment

  • CPython versions tested on: 3.10.8
  • Operating system and architecture: Linux x86
@Gregofi Gregofi added the type-bug An unexpected behavior, bug, or error label Dec 21, 2022
@ericvsmith
Copy link
Member

ericvsmith commented Dec 21, 2022

I don't think it's documented to do so, is it? If it's not, then this is a feature request.

What I do is just change the positional argument to use underscores.

@rhettinger rhettinger added type-feature A feature request or enhancement and removed type-bug An unexpected behavior, bug, or error labels Dec 30, 2022
@erlend-aasland erlend-aasland moved this to Features in Argparse issues Feb 21, 2023
@iritkatriel iritkatriel added the stdlib Python modules in the Lib dir label Nov 27, 2023
@vadmium
Copy link
Member

vadmium commented May 4, 2024

Looks the same as #95100

@serhiy-storchaka
Copy link
Member

Closing as a duplicate of #95100.

@serhiy-storchaka serhiy-storchaka closed this as not planned Won't fix, can't repro, duplicate, stale Oct 9, 2024
@github-project-automation github-project-automation bot moved this from Features to Doc issues in Argparse issues Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir type-feature A feature request or enhancement
Projects
Status: Doc issues
Development

No branches or pull requests

6 participants