Skip to content

Commit ead403b

Browse files
picnixzsrinivasreddy
authored andcommitted
pythongh-127413: allow to show specialized bytecode via dis CLI (python#127414)
1 parent f2e4894 commit ead403b

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

Doc/library/dis.rst

+7-1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ interpreter.
6060
The :option:`-P <dis --show-positions>` command-line option
6161
and the ``show_positions`` argument were added.
6262

63+
The :option:`-S <dis --specialized>` command-line option is added.
64+
6365
Example: Given the function :func:`!myfunc`::
6466

6567
def myfunc(alist):
@@ -89,7 +91,7 @@ The :mod:`dis` module can be invoked as a script from the command line:
8991

9092
.. code-block:: sh
9193
92-
python -m dis [-h] [-C] [-O] [-P] [infile]
94+
python -m dis [-h] [-C] [-O] [-P] [-S] [infile]
9395
9496
The following options are accepted:
9597

@@ -111,6 +113,10 @@ The following options are accepted:
111113

112114
Show positions of instructions in the source code.
113115

116+
.. cmdoption:: -S, --specialized
117+
118+
Show specialized bytecode.
119+
114120
If :file:`infile` is specified, its disassembled code will be written to stdout.
115121
Otherwise, disassembly is performed on compiled source code received from stdin.
116122

Doc/whatsnew/3.14.rst

+6
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,18 @@ dis
348348
This feature is also exposed via :option:`dis --show-positions`.
349349
(Contributed by Bénédikt Tran in :gh:`123165`.)
350350

351+
* Add the :option:`dis --specialized` command-line option to
352+
show specialized bytecode.
353+
(Contributed by Bénédikt Tran in :gh:`127413`.)
354+
355+
351356
errno
352357
-----
353358

354359
* Add :data:`errno.EHWPOISON` error code.
355360
(Contributed by James Roy in :gh:`126585`.)
356361

362+
357363
fractions
358364
---------
359365

Lib/dis.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,8 @@ def main():
11251125
help='show instruction offsets')
11261126
parser.add_argument('-P', '--show-positions', action='store_true',
11271127
help='show instruction positions')
1128+
parser.add_argument('-S', '--specialized', action='store_true',
1129+
help='show specialized bytecode')
11281130
parser.add_argument('infile', nargs='?', default='-')
11291131
args = parser.parse_args()
11301132
if args.infile == '-':
@@ -1135,7 +1137,8 @@ def main():
11351137
with open(args.infile, 'rb') as infile:
11361138
source = infile.read()
11371139
code = compile(source, name, "exec")
1138-
dis(code, show_caches=args.show_caches, show_offsets=args.show_offsets, show_positions=args.show_positions)
1140+
dis(code, show_caches=args.show_caches, adaptive=args.specialized,
1141+
show_offsets=args.show_offsets, show_positions=args.show_positions)
11391142

11401143
if __name__ == "__main__":
11411144
main()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add the :option:`dis --specialized` command-line option to show specialized
2+
bytecode. Patch by Bénédikt Tran.

0 commit comments

Comments
 (0)