https://github.com/python/cpython/commit/aa41833e9f47c49bed85f0e44cde9c3ceaefc69f
commit: aa41833e9f47c49bed85f0e44cde9c3ceaefc69f
branch: 3.14
author: Miss Islington (bot) <[email protected]>
committer: gpshead <[email protected]>
date: 2026-09-08T05:25:23Z
summary:
[3.14] gh-157159: improve the tabnanny usage message (GH-157160) (#157164)
gh-157159: improve the tabnanny usage message (GH-157160)
The usage message embedded sys.argv[0], which under `python -m tabnanny`
is the absolute path of tabnanny.py, and a meaningless virtual path when
the standard library is in a zip archive or embedded in an executable.
Print f"Usage: {sys.executable} -m tabnanny [-v] file_or_directory ..."
instead, and make the test expect that fixed form.
(cherry picked from commit 5ddd59fc474a7e0b77b6f8cb0ba678254171b106)
Co-authored-by: Gregory P. Smith <[email protected]>
files:
A Misc/NEWS.d/next/Library/2026-09-08-09-30-00.gh-issue-157159.tabNny.rst
M Lib/tabnanny.py
M Lib/test/test_tabnanny.py
diff --git a/Lib/tabnanny.py b/Lib/tabnanny.py
index c0097351b269f2..32ae86ca7612b5 100644
--- a/Lib/tabnanny.py
+++ b/Lib/tabnanny.py
@@ -49,7 +49,7 @@ def main():
if o == '-v':
verbose = verbose + 1
if not args:
- errprint("Usage:", sys.argv[0], "[-v] file_or_directory ...")
+ errprint(f"Usage: {sys.executable} -m tabnanny [-v] file_or_directory
...")
for arg in args:
check(arg)
diff --git a/Lib/test/test_tabnanny.py b/Lib/test/test_tabnanny.py
index 30dcb3e3c4f4f9..916f253d9fcb86 100644
--- a/Lib/test/test_tabnanny.py
+++ b/Lib/test/test_tabnanny.py
@@ -6,12 +6,12 @@
from unittest import TestCase, mock
import errno
import os
+import sys
import tabnanny
import tokenize
import tempfile
import textwrap
-from test.support import (captured_stderr, captured_stdout, script_helper,
- findfile)
+from test.support import captured_stderr, captured_stdout, script_helper
from test.support.os_helper import unlink
@@ -327,8 +327,7 @@ def test_with_error_free_file(self):
def test_command_usage(self):
"""Should display usage on no arguments."""
- path = findfile('tabnanny.py')
- stderr = f"Usage: {path} [-v] file_or_directory ..."
+ stderr = f"Usage: {sys.executable} -m tabnanny [-v] file_or_directory
..."
self.validate_cmd(stderr=stderr, expect_failure=True)
def test_quiet_flag(self):
diff --git
a/Misc/NEWS.d/next/Library/2026-09-08-09-30-00.gh-issue-157159.tabNny.rst
b/Misc/NEWS.d/next/Library/2026-09-08-09-30-00.gh-issue-157159.tabNny.rst
new file mode 100644
index 00000000000000..982c4afb43dac1
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2026-09-08-09-30-00.gh-issue-157159.tabNny.rst
@@ -0,0 +1,2 @@
+The usage message printed by ``python -m tabnanny`` when no arguments are
+given now suggests ``python -m`` instead of the source file.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]