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: Multiple "unknown option" errors when passing unknown arguments to the interpreter
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.9, Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: The Compiler, corona10, hieu.nguyen, miss-islington, serhiy.storchaka, tweksteen, vstinner
Priority: normal Keywords: patch

Created on 2020-05-06 09:32 by The Compiler, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 19955 merged vstinner, 2020-05-06 12:58
PR 19956 merged miss-islington, 2020-05-06 13:22
Messages (8)
msg368231 - (view) Author: Florian Bruhin (The Compiler) * Date: 2020-05-06 09:32
A minor issue I just discovered today: When e.g. doing "python3 --foo", the output is:

  unknown option --foo
  unknown option --foo
  unknown option --foo
  usage: /usr/bin/python3 [option] ... [-c cmd | -m mod | file | -] [arg] ...

With more dashes in the options, it seems to get worse:

  unknown option --foo-bar-baz
  unknown option --foo-bar-baz
  unknown option --foo-bar-baz
  unknown option --foo-bar-baz
  unknown option --foo-bar-baz
  unknown option --foo-bar-baz
  unknown option --foo-bar-baz
  usage: /usr/bin/python3 [option] ... [-c cmd | -m mod | file | -] [arg] ...

This seems very similar to issue16306 (thus why I added people involved there to the nosy list), except that it happens with long rather than short arguments.

This only happens with Python 3.8/3.9, not 3.7 or older. I was able to bisect this to the following commit:

commit 6dcb54228e7520abd058897440c26e323f62afcd
Author: Victor Stinner <vstinner@redhat.com>
Date:   Tue Mar 5 02:44:12 2019 +0100

    bpo-36142: Add _PyPreConfig_ReadFromArgv() (GH-12173)
    
    The new function is now responsible to parse -E and -I command line
    arguments.
msg368244 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-05-06 12:59
Oh right, that's because Python parses the command line at least 3 times :-) The first 2 times, it is not supposed to log errors. It's a bug: attached PR 19955 fix it.
msg368246 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-05-06 13:00
> I was able to bisect this to the following commit: (...)

Oh, well done! Yeah, it's all my fault ;-) It's a regression of the PEP 587 (PyConfig) implementation.

I chose to share code between Python/preconfig.c and Python/initconfig.c rather than duplicate code. The implementation of _PyPreConfig_Read() and PyConfig_Read() is quite complex.
msg368249 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-05-06 13:22
New changeset 2668a9a5aa506a048aef7b4881c8dcf6b81c6870 by Victor Stinner in branch 'master':
bpo-40527: Fix command line argument parsing (GH-19955)
https://github.com/python/cpython/commit/2668a9a5aa506a048aef7b4881c8dcf6b81c6870
msg368253 - (view) Author: miss-islington (miss-islington) Date: 2020-05-06 13:43
New changeset bce4ddafdd188cc6deb1584728b67b9e149ca6a4 by Miss Islington (bot) in branch '3.8':
bpo-40527: Fix command line argument parsing (GH-19955)
https://github.com/python/cpython/commit/bce4ddafdd188cc6deb1584728b67b9e149ca6a4
msg368259 - (view) Author: Dong-hee Na (corona10) * (Python committer) Date: 2020-05-06 14:41
Thanks for the bug report Florian and for work Victor!

I am now closing this issue :)
msg368265 - (view) Author: Florian Bruhin (The Compiler) * Date: 2020-05-06 15:21
That was an insanely fast fix - thanks everyone! :)
msg368275 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-05-06 16:17
> That was an insanely fast fix - thanks everyone! :)

Sorry about that. We are working on this issue to ensure that next bugs will not fixed as quickly a this done ;-)
History
Date User Action Args
2022-04-11 14:59:30adminsetgithub: 84707
2020-05-06 16:17:31vstinnersetmessages: + msg368275
2020-05-06 15:21:07The Compilersetmessages: + msg368265
2020-05-06 14:41:54corona10setstatus: open -> closed
resolution: fixed
messages: + msg368259

stage: patch review -> resolved
2020-05-06 13:43:13miss-islingtonsetmessages: + msg368253
2020-05-06 13:22:48miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request19272
2020-05-06 13:22:21corona10setnosy: + corona10
messages: + msg368249
2020-05-06 13:00:23vstinnersetmessages: + msg368246
2020-05-06 12:59:03vstinnersetmessages: + msg368244
2020-05-06 12:58:04vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request19271
2020-05-06 09:32:05The Compilercreate