This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Incorrect assignment of optional argument when partial match with different argument found.
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eric.smith, rob-dalton, zach.ware
Priority: normal Keywords:

Created on 2018-10-01 20:36 by rob-dalton, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg326824 - (view) Author: Rob Dalton (rob-dalton) Date: 2018-10-01 20:36
Parsing an unknown optional argument whose leading characters (e.g. '--user') match those of another, known optional argument (e.g. '--userdata') causes the unknown argument to be parsed as the known one.

For example - passing the unknown argument '--user' to a parser with the known argument '--userdata' assigns the passed '--user' value to '--userdata'.

Here's my setup info:
  Python: Python 3.6.3 :: Anaconda custom (64-bit)
  OS: MacOS High Sierra 10.13.6 

Wrote up some example cases here:
  https://gist.github.com/rob-dalton/9ec06b8d5e2e9083713ddc7884d16072
msg326828 - (view) Author: Zachary Ware (zach.ware) * (Python committer) Date: 2018-10-01 20:48
Would using `allow_abbrev=False` fix this for you?

https://docs.python.org/3/library/argparse.html#allow-abbrev
msg326830 - (view) Author: Rob Dalton (rob-dalton) Date: 2018-10-01 21:02
It does. Thanks! I feel dumb for not finding that.

Guess I'd just suggest making the default `false`, seems more intuitive to
me.

On Mon, Oct 1, 2018 at 2:00 PM Robert Dalton <rob.c.dalton@gmail.com> wrote:

> It does. Thanks! I feel dumb for not finding that.
>
> Guess I'd just suggest making the default `false`, seems more intuitive to
> me.
>
> On Mon, Oct 1, 2018 at 1:48 PM Zachary Ware <report@bugs.python.org>
> wrote:
>
>>
>> Zachary Ware <zachary.ware@gmail.com> added the comment:
>>
>> Would using `allow_abbrev=False` fix this for you?
>>
>> https://docs.python.org/3/library/argparse.html#allow-abbrev
>>
>> ----------
>> nosy: +zach.ware
>>
>> _______________________________________
>> Python tracker <report@bugs.python.org>
>> <https://bugs.python.org/issue34865>
>> _______________________________________
>>
>
>
> --
> Best,
> Rob Dalton
>
>
> (814) 571-0462 | robdalton.me | robcdalton@gmail.com
>

-- 
Best,
Rob Dalton

(814) 571-0462 | robdalton.me | robcdalton@gmail.com
msg326836 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-10-01 23:06
As much as I agree that allow_abbrev=False would be a much better default, at this point we can't change it. Doing so would break who knows how many existing scripts when they upgraded Python versions.
History
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 79046
2018-10-01 23:06:03eric.smithsetstatus: open -> closed

nosy: + eric.smith
messages: + msg326836

resolution: not a bug
stage: resolved
2018-10-01 21:02:07rob-daltonsetmessages: + msg326830
2018-10-01 20:48:40zach.waresetnosy: + zach.ware
messages: + msg326828
2018-10-01 20:36:46rob-daltoncreate