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 does not accept negative args w/ exponents as for negative arguments #96994

Open
mwette opened this issue Sep 21, 2022 · 0 comments
Open
Labels
type-bug An unexpected behavior, bug, or error

Comments

@mwette
Copy link

mwette commented Sep 21, 2022

Bug report

In the "Arguments Containing -" section of the argparse documentation it says:

positional arguments may only begin with - if they look like negative numbers and there are no options in the parser that look like negative numbers

However, negative numbers with exponent notation are rejected. I feel this is a bug.

With file apbug.py containing

#!/usr/bin/env python3.10

import argparse

ap = argparse.ArgumentParser()
ap.add_argument("maybe_neg", default=False)

print("try -3.0"); args = ap.parse_args(args=["-3.0",])
print("try -3.0e0"); args = ap.parse_args(args=["-3.0e0",])

execution results in

$ ./apbug.py 
try -3.0
try -3.0e0
usage: apbug.py [-h] maybe_neg
apbug.py: error: the following arguments are required: maybe_neg

Your environment

  • CPython versions tested on: 3.10
  • Operating system and architecture: macOS 12.6 x86_64
@mwette mwette added the type-bug An unexpected behavior, bug, or error label Sep 21, 2022
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

1 participant