https://github.com/python/cpython/commit/85c04f80fd3a3098674f60038f248c076a476acf
commit: 85c04f80fd3a3098674f60038f248c076a476acf
branch: main
author: Semyon Moroz <donbar...@proton.me>
committer: hugovk <1324225+hug...@users.noreply.github.com>
date: 2025-03-17T09:36:30Z
summary:

gh-93096: Update and document `pickletools` CLI (#131273)

files:
M Doc/library/pickletools.rst
M Lib/pickletools.py

diff --git a/Doc/library/pickletools.rst b/Doc/library/pickletools.rst
index e072605974f6c2..30fc2962e0bf78 100644
--- a/Doc/library/pickletools.rst
+++ b/Doc/library/pickletools.rst
@@ -19,7 +19,7 @@ ordinary users of the :mod:`pickle` module probably won't 
find the
 
 .. _pickletools-cli:
 
-Command line usage
+Command-line usage
 ------------------
 
 .. versionadded:: 3.2
@@ -48,7 +48,7 @@ For example, with a tuple ``(1, 2)`` pickled in file 
``x.pickle``:
         9: .    STOP
     highest protocol among opcodes = 2
 
-Command line options
+Command-line options
 ^^^^^^^^^^^^^^^^^^^^
 
 .. program:: pickletools
@@ -72,12 +72,16 @@ Command line options
 
 .. option:: -p, --preamble=<preamble>
 
-   When more than one pickle file are specified, print given preamble
+   When more than one pickle file is specified, print given preamble
    before each disassembly.
 
+.. option:: pickle_file
 
+   A pickle file to read, or ``-`` to indicate reading from standard input.
 
-Programmatic Interface
+
+
+Programmatic interface
 ----------------------
 
 
diff --git a/Lib/pickletools.py b/Lib/pickletools.py
index 02aad12985dafe..53f25ea4e46b4d 100644
--- a/Lib/pickletools.py
+++ b/Lib/pickletools.py
@@ -2845,7 +2845,7 @@ def __init__(self, value):
         description='disassemble one or more pickle files')
     parser.add_argument(
         'pickle_file',
-        nargs='*', help='the pickle file')
+        nargs='+', help='the pickle file')
     parser.add_argument(
         '-o', '--output',
         help='the file where the output should be written')
@@ -2863,26 +2863,23 @@ def __init__(self, value):
         help='if more than one pickle file is specified, print this before'
         ' each disassembly')
     args = parser.parse_args()
-    if not args.pickle_file:
-        parser.print_help()
+    annotate = 30 if args.annotate else 0
+    memo = {} if args.memo else None
+    if args.output is None:
+        output = sys.stdout
     else:
-        annotate = 30 if args.annotate else 0
-        memo = {} if args.memo else None
-        if args.output is None:
-            output = sys.stdout
-        else:
-            output = open(args.output, 'w')
-        try:
-            for arg in args.pickle_file:
-                if len(args.pickle_file) > 1:
-                    name = '<stdin>' if arg == '-' else arg
-                    preamble = args.preamble.format(name=name)
-                    output.write(preamble + '\n')
-                if arg == '-':
-                    dis(sys.stdin.buffer, output, memo, args.indentlevel, 
annotate)
-                else:
-                    with open(arg, 'rb') as f:
-                        dis(f, output, memo, args.indentlevel, annotate)
-        finally:
-            if output is not sys.stdout:
-                output.close()
+        output = open(args.output, 'w')
+    try:
+        for arg in args.pickle_file:
+            if len(args.pickle_file) > 1:
+                name = '<stdin>' if arg == '-' else arg
+                preamble = args.preamble.format(name=name)
+                output.write(preamble + '\n')
+            if arg == '-':
+                dis(sys.stdin.buffer, output, memo, args.indentlevel, annotate)
+            else:
+                with open(arg, 'rb') as f:
+                    dis(f, output, memo, args.indentlevel, annotate)
+    finally:
+        if output is not sys.stdout:
+            output.close()

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to