Skip to content

argparse does not handle hyphens in positional arguments #100411

Closed as not planned
@Gregofi

Description

@Gregofi

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtype-featureA feature request or enhancement

    Projects

    Status

    Doc issues

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions