Skip to content

GH-155009: Preserve argparse prog for programmatic module-as-main execution - #155199

Merged
savannahostrowski merged 5 commits into
python:mainfrom
savannahostrowski:gh-155009-argparse-prog
Aug 5, 2026
Merged

GH-155009: Preserve argparse prog for programmatic module-as-main execution#155199
savannahostrowski merged 5 commits into
python:mainfrom
savannahostrowski:gh-155009-argparse-prog

Conversation

@savannahostrowski

@savannahostrowskisavannahostrowski commented Aug 5, 2026

Copy link
Copy Markdown
Member

I opted to compare sys.argv[0] with __main__.__spec__.origin because looking for an adjacent -m, module pair in sys.orig_argv can mistake application arguments for an interpreter option and miss valid forms such as -mmodule.

@savannahostrowski
savannahostrowski enabled auto-merge (squash) August 5, 2026 04:10
@savannahostrowski
savannahostrowski merged commit ca4518b into python:mainAug 5, 2026
50 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @savannahostrowski for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

Copy link
Copy Markdown

GH-155200 is a backport of this pull request to the 3.15 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Aug 5, 2026
@bedevere-app

Copy link
Copy Markdown

GH-155201 is a backport of this pull request to the 3.14 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.14 bugs and security fixes label Aug 5, 2026
savannahostrowski added a commit that referenced this pull request Aug 5, 2026
…ain execution (GH-155199) (#155201)
GH-155009: Preserve argparse prog for programmatic module-as-main execution (GH-155199)
(cherry picked from commit ca4518b)
Co-authored-by: Savannah Ostrowski <savannah@python.org>
@bedevere-bot

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot ARM64 Raspbian 3.14 (tier-3) has failed when building commit d9f94ee.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1764/builds/1409) and take a look at the build logs.
  4. Check if the failure is related to this commit (d9f94ee) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1764/builds/1409

Failed tests:

  • test_argparse

Failed subtests:

  • test_module_as_main_without_altering_argv - test.test_argparse.TestProgName.test_module_as_main_without_altering_argv

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
File "/home/stan/buildarea/3.14.stan-raspbian.nondebug/build/Lib/test/test_argparse.py", line 7141, in test_module_as_main_without_altering_argvself.check_usage(os.path.basename(runner), runner,
~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^PYTHONPATH=os.curdir)
^^^^^^^^^^^^^^^^^^^^^
File "/home/stan/buildarea/3.14.stan-raspbian.nondebug/build/Lib/test/test_argparse.py", line 7098, in check_usage
res = script_helper.assert_python_ok('-Xutf8', *args, '-h', **kwargs)
File "/home/stan/buildarea/3.14.stan-raspbian.nondebug/build/Lib/test/support/script_helper.py", line 182, in assert_python_okreturn _assert_python(True, *args, **env_vars)
File "/home/stan/buildarea/3.14.stan-raspbian.nondebug/build/Lib/test/support/script_helper.py", line 167, in _assert_python
res.fail(cmd_line)
~~~~~~~~^^^^^^^^^^
File "/home/stan/buildarea/3.14.stan-raspbian.nondebug/build/Lib/test/support/script_helper.py", line 80, in failraiseAssertionError(f"Process return code is {exitcode}\n"...<10 lines>...f"---")
AssertionError: Process return code is 1
command line: ['/home/stan/buildarea/3.14.stan-raspbian.nondebug/build/python', '-X', 'faulthandler', '-Xutf8', 'packageæ/runner.py', '-h']

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@savannahostrowski@bedevere-bot@itamaro