]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-127413: allow to show specialized bytecode via `dis` CLI (#127414)
authorBénédikt Tran <10796600+picnixz@users.noreply.github.com>
Thu, 5 Dec 2024 15:01:59 +0000 (16:01 +0100)
committerGitHub <noreply@github.com>
Thu, 5 Dec 2024 15:01:59 +0000 (15:01 +0000)
Doc/library/dis.rst
Doc/whatsnew/3.14.rst
Lib/dis.py
Misc/NEWS.d/next/Library/2024-11-29-14-45-26.gh-issue-127413.z11AUc.rst [new file with mode: 0644]

index e2926f2440af6da13a68aaa2e461a5122a331d2a..f8f4188d27b472fad4e5e308c27f355cd3ed80d9 100644 (file)
@@ -60,6 +60,8 @@ interpreter.
       The :option:`-P <dis --show-positions>` command-line option
       and the ``show_positions`` argument were added.
 
+      The :option:`-S <dis --specialized>` command-line option is added.
+
 Example: Given the function :func:`!myfunc`::
 
    def myfunc(alist):
@@ -89,7 +91,7 @@ The :mod:`dis` module can be invoked as a script from the command line:
 
 .. code-block:: sh
 
-   python -m dis [-h] [-C] [-O] [-P] [infile]
+   python -m dis [-h] [-C] [-O] [-P] [-S] [infile]
 
 The following options are accepted:
 
@@ -111,6 +113,10 @@ The following options are accepted:
 
    Show positions of instructions in the source code.
 
+.. cmdoption:: -S, --specialized
+
+   Show specialized bytecode.
+
 If :file:`infile` is specified, its disassembled code will be written to stdout.
 Otherwise, disassembly is performed on compiled source code received from stdin.
 
index 52a6d6e43401940a0831296c2f17848b65315625..e83c509a025ab544cf9121f3da071b3217c677b2 100644 (file)
@@ -348,12 +348,18 @@ dis
   This feature is also exposed via :option:`dis --show-positions`.
   (Contributed by Bénédikt Tran in :gh:`123165`.)
 
+* Add the :option:`dis --specialized` command-line option to
+  show specialized bytecode.
+  (Contributed by Bénédikt Tran in :gh:`127413`.)
+
+
 errno
 -----
 
 * Add :data:`errno.EHWPOISON` error code.
   (Contributed by James Roy in :gh:`126585`.)
 
+
 fractions
 ---------
 
index 1718e39cceb638122e9c8b5712d97b10b394a143..6b3e9ef8399e1c51aca2b0f5e5ec9579714f1b13 100644 (file)
@@ -1125,6 +1125,8 @@ def main():
                         help='show instruction offsets')
     parser.add_argument('-P', '--show-positions', action='store_true',
                         help='show instruction positions')
+    parser.add_argument('-S', '--specialized', action='store_true',
+                        help='show specialized bytecode')
     parser.add_argument('infile', nargs='?', default='-')
     args = parser.parse_args()
     if args.infile == '-':
@@ -1135,7 +1137,8 @@ def main():
         with open(args.infile, 'rb') as infile:
             source = infile.read()
     code = compile(source, name, "exec")
-    dis(code, show_caches=args.show_caches, show_offsets=args.show_offsets, show_positions=args.show_positions)
+    dis(code, show_caches=args.show_caches, adaptive=args.specialized,
+        show_offsets=args.show_offsets, show_positions=args.show_positions)
 
 if __name__ == "__main__":
     main()
diff --git a/Misc/NEWS.d/next/Library/2024-11-29-14-45-26.gh-issue-127413.z11AUc.rst b/Misc/NEWS.d/next/Library/2024-11-29-14-45-26.gh-issue-127413.z11AUc.rst
new file mode 100644 (file)
index 0000000..2330fb6
--- /dev/null
@@ -0,0 +1,2 @@
+Add the :option:`dis --specialized` command-line option to show specialized
+bytecode. Patch by Bénédikt Tran.