[issue44208] argparse: Accept option without needing to distinguish "-" from "_" in arg_string

2021-05-25 Thread Catherine Devlin


Catherine Devlin  added the comment:

All that said, it's easy to imagine a PyPI package that would give this 
functionality for those who want it.  Maybe even one that could also alter the 
behavior of Click and Typer.  If you want to go that route, let me know.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44208] argparse: Accept option without needing to distinguish "-" from "_" in arg_string

2021-05-25 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

William, thank you for the suggestion, but we're going to decline for the 
reasons listed by Eric and me.

--
resolution:  -> rejected
stage: patch review -> resolved
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44208] argparse: Accept option without needing to distinguish "-" from "_" in arg_string

2021-05-25 Thread Eric V. Smith


Eric V. Smith  added the comment:

I agree with Raymond: I've never seen this behavior anywhere. In general, I 
think being looser with allowed inputs is not a good idea.

--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44208] argparse: Accept option without needing to distinguish "-" from "_" in arg_string

2021-05-21 Thread Raymond Hettinger


Raymond Hettinger  added the comment:

Ideally, we should keep argparse in line with common practices.  AFAICT, 
treating '-' and '_' the same isn't a norm.  Click, for example, doesn't do 
this.

--
nosy: +rhettinger
versions:  -Python 3.10, Python 3.6, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44208] argparse: Accept option without needing to distinguish "-" from "_" in arg_string

2021-05-21 Thread Raymond Hettinger


Change by Raymond Hettinger :


--
nosy: +paul.j3

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44208] argparse: Accept option without needing to distinguish "-" from "_" in arg_string

2021-05-21 Thread William Barnhart


William Barnhart  added the comment:

I'm glad someone else thinks it's a good idea. If you have some ideas for 
tests, I'd be happy to help write them in order to spare the inconvenience 
(unless the tests are that easy to write then by all means please do). 

I can appreciate why the core developers could be polarized. One side could say 
it's safer to just take better care of our Python scripts and have them in 
wrapper functions. But people don't always do this.

In favor of the idea: This method can be used to spare developers from agony 
when a "_" is changed to a "-" when they aren't informed of the change. As a 
result, this can allow for code to remain usable since most developers are more 
interested in the letters of arguments and not so much special characters. But 
then again, a --help option could be all that's needed to fix this issue.

I think a solution that satisfies both parties would be creating some safe 
guard for adding arguments that are named identically, containing "_" or "-" in 
the middle, and raising an exception when the regexes of the arguments are 
conflicting. Such as if I wrote:
```
parser.add_argument('--please_work')
parser.add_argument('--please-work')
```
then an exception should be raised with an error for conflicting argument names.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44208] argparse: Accept option without needing to distinguish "-" from "_" in arg_string

2021-05-21 Thread Catherine Devlin


Catherine Devlin  added the comment:

Your PR doesn't include any tests... but I like the idea enough to create the 
tests for you if you prefer.

However, first I'd like to see whether the core devs like the idea.  I could 
see saying either "yes, why not make things easy" or "no, there should be only 
one way to do it".

--
nosy: +catherinedevlin

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44208] argparse: Accept option without needing to distinguish "-" from "_" in arg_string

2021-05-21 Thread William Barnhart


Change by William Barnhart :


--
keywords: +patch
pull_requests: +24899
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/26295

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue44208] argparse: Accept option without needing to distinguish "-" from "_" in arg_string

2021-05-21 Thread William Barnhart


New submission from William Barnhart :

An issue I encountered recently with argparse was when I tried running a script 
with its argument changed from something like:
```
parser.add_argument('--please_work')
```
and was replaced with:
```
parser.add_argument('--please-work')
```

I have not ever seen anyone add an argument where a function has two arguments 
existing in a function, such as please_work and please-work. I think this is a 
pretty safe feature to implement, plus it enforces good practices. So if I 
wrote something such as:

```
parser = argparse.ArgumentParser(description="check this out")
parser.add_argument('--please-work')
```

Then I could call the program using:
```
python3 test.py --please_work True
```
or:
```
python3 test.py --please-work True
```

--
components: Library (Lib)
messages: 394135
nosy: wbarnha
priority: normal
severity: normal
status: open
title: argparse: Accept option without needing to distinguish "-" from "_" in 
arg_string
type: enhancement
versions: Python 3.10, Python 3.11, Python 3.6, Python 3.7, Python 3.8, Python 
3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com