classification
Title: argparse: allow_abbrev=False is ignored for alternative prefix characters
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: kyleam, miss-islington, paul.j3, rhettinger, shihai1991
Priority: normal Keywords: patch

Created on 2020-02-03 20:11 by kyleam, last changed 2020-03-03 16:30 by petr.viktorin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 18337 merged kyleam, 2020-02-03 20:18
PR 18543 merged miss-islington, 2020-02-18 09:49
Messages (4)
msg361326 - (view) Author: Kyle Meyer (kyleam) * Date: 2020-02-03 20:11
As of Python v3.8.0 (specifically commit b1e4d1b603), specifying
`allow_abbrev=False` does not disable abbreviation for prefix
characters other than '-'.

--8<---------------cut here---------------start------------->8---
import argparse

parser = argparse.ArgumentParser(prefix_chars='+', allow_abbrev=False)
parser.add_argument('++long')
print(parser.parse_args(['++lo=val']))
--8<---------------cut here---------------end--------------->8---

Observed output (with b1e4d1b603 and current master):

    Namespace(long='val')

Expected (and observed with b1e4d1b603^ and 3.7.3):

    usage: scratch.py [+h] [++long LONG]
    scratch.py: error: unrecognized arguments: ++lo=val


I will follow up with a PR to propose a fix.
msg361345 - (view) Author: hai shi (shihai1991) * Date: 2020-02-04 12:06
Good catch, it apprears in my python env(master base) too.
msg362183 - (view) Author: miss-islington (miss-islington) Date: 2020-02-18 09:49
New changeset 8edfc47baec7ff4cb1b9db83dd35c8ffc1d498a4 by Kyle Meyer in branch 'master':
bpo-39546: argparse: Honor allow_abbrev=False for specified prefix_chars (GH-18337)
https://github.com/python/cpython/commit/8edfc47baec7ff4cb1b9db83dd35c8ffc1d498a4
msg362193 - (view) Author: miss-islington (miss-islington) Date: 2020-02-18 11:14
New changeset e412cbba52e7cf6699720d99a4b88baef92db7b2 by Miss Islington (bot) in branch '3.8':
[3.8] bpo-39546: argparse: Honor allow_abbrev=False for specified prefix_chars (GH-18337) (GH-18543)
https://github.com/python/cpython/commit/e412cbba52e7cf6699720d99a4b88baef92db7b2
History
Date User Action Args
2020-03-03 16:30:56petr.viktorinsetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-02-18 11:14:11miss-islingtonsetmessages: + msg362193
2020-02-18 09:49:13miss-islingtonsetpull_requests: + pull_request17920
2020-02-18 09:49:07miss-islingtonsetnosy: + miss-islington
messages: + msg362183
2020-02-04 12:06:25shihai1991setnosy: + shihai1991, rhettinger, paul.j3
messages: + msg361345
2020-02-03 20:18:15kyleamsetkeywords: + patch
stage: patch review
pull_requests: + pull_request17709
2020-02-03 20:11:28kyleamcreate