[issue44208] argparse: Accept option without needing to distinguish "-" from "_" in arg_string
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 <https://bugs.python.org/issue44208> ___ ___ 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
Change by William Barnhart : -- keywords: +patch pull_requests: +24899 stage: -> patch review pull_request: https://github.com/python/cpython/pull/26295 ___ Python tracker <https://bugs.python.org/issue44208> ___ ___ 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
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 <https://bugs.python.org/issue44208> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com