-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathdis.html
More file actions
2739 lines (2506 loc) · 227 KB
/
Copy pathdis.html
File metadata and controls
2739 lines (2506 loc) · 227 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="fa" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="dis --- Disassembler for Python bytecode" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/library/dis.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="Source code: Lib/dis.py The dis module supports the analysis of CPython bytecode by disassembling it. The CPython bytecode which this module takes as an input is defined in the file Include/opcode...." />
<meta property="og:image" content="_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="Source code: Lib/dis.py The dis module supports the analysis of CPython bytecode by disassembling it. The CPython bytecode which this module takes as an input is defined in the file Include/opcode...." />
<meta name="theme-color" content="#3776ab">
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<title>dis --- Disassembler for Python bytecode — مستندات Python3.14.6</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=4365c8fe" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=0fc419ee" />
<script src="../_static/documentation_options.js?v=e254dbbb"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/translations.js?v=5df48d09"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="جستجو در مستندات Python3.14.6"
href="../_static/opensearch.xml"/>
<link rel="author" title="درباره این مستندات" href="../about.html" />
<link rel="index" title="فهرست" href="../genindex.html" />
<link rel="search" title="جستجو" href="../search.html" />
<link rel="copyright" title="حق چاپ" href="../copyright.html" />
<link rel="next" title="pickletools --- Tools for pickle developers" href="pickletools.html" />
<link rel="prev" title="compileall --- Byte-compile Python libraries" href="compileall.html" />
<link rel="canonical" href="https://docs.python.org/3/library/dis.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg">
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo">
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
</svg>
<input placeholder="جستجو سریع" aria-label="جستجو سریع" type="search" name="q">
<input type="submit" value="برو">
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">فهرست عناوین</a></h3>
<ul>
<li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code> --- Disassembler for Python bytecode</a><ul>
<li><a class="reference internal" href="#command-line-interface">Command-line interface</a></li>
<li><a class="reference internal" href="#bytecode-analysis">Bytecode analysis</a></li>
<li><a class="reference internal" href="#analysis-functions">Analysis functions</a></li>
<li><a class="reference internal" href="#python-bytecode-instructions">Python Bytecode Instructions</a></li>
<li><a class="reference internal" href="#opcode-collections">Opcode collections</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>موضوع قبلی</h4>
<p class="topless"><a href="compileall.html"
title="فصل قبلی"><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> --- Byte-compile Python libraries</a></p>
</div>
<div>
<h4>موضوع بعدی</h4>
<p class="topless"><a href="pickletools.html"
title="فصل بعدی"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pickletools</span></code> --- Tools for pickle developers</a></p>
</div>
<script>
document.addEventListener('DOMContentLoaded', () => {
const title = document.querySelector('meta[property="og:title"]').content;
const elements = document.querySelectorAll('.improvepage');
const pageurl = window.location.href.split('?')[0];
elements.forEach(element => {
const url = new URL(element.href.split('?')[0].replace("-nojs", ""));
url.searchParams.set('pagetitle', title);
url.searchParams.set('pageurl', pageurl);
url.searchParams.set('pagesource', "library/dis.rst");
element.href = url.toString();
});
});
</script>
<div role="note" aria-label="source link">
<h3>این صفحه</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">گزارش یک اشکال</a></li>
<li><a class="improvepage" href="../improve-page-nojs.html">بهبود این صفحه</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/library/dis.rst?plain=1"
rel="nofollow">نمایش منبع
</a>
</li>
<li>
<a href="https://github.com/python/python-docs-fa/blob/3.14/library/dis.po?plain=1"
rel="nofollow">نمایش منبع ترجمه</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>ناوبری</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="فهرست کلی"
accesskey="I">فهرست</a></li>
<li class="right" >
<a href="../py-modindex.html" title="نمایه ی ماژول های پایتون"
>ماژول ها</a> |</li>
<li class="right" >
<a href="pickletools.html" title="pickletools --- Tools for pickle developers"
accesskey="N">بعدی</a> |</li>
<li class="right" >
<a href="compileall.html" title="compileall --- Byte-compile Python libraries"
accesskey="P">قبلی</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>
<li><a href="https://www.python.org/">Python</a> »</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.14.6 Documentation</a> »
</li>
<li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>
<li class="nav-item nav-item-2"><a href="language.html" accesskey="U">Python Language Services</a> »</li>
<li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code> --- Disassembler for Python bytecode</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="جستجو سریع" aria-label="جستجو سریع" type="search" name="q" id="search-box">
<input type="submit" value="برو">
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="module-dis">
<span id="dis-disassembler-for-python-bytecode"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code> --- Disassembler for Python bytecode<a class="headerlink" href="#module-dis" title="Link to this heading">¶</a></h1>
<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.14/Lib/dis.py">Lib/dis.py</a></p>
<hr class="docutils" />
<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code> module supports the analysis of CPython <a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a> by
disassembling it. The CPython bytecode which this module takes as an input is
defined in the file <code class="file docutils literal notranslate"><span class="pre">Include/opcode.h</span></code> and used by the compiler and the
interpreter.</p>
<div class="impl-detail compound">
<p><strong>جزئیات پیادهسازی در CPython:</strong> Bytecode is an implementation detail of the CPython interpreter. No
guarantees are made that bytecode will not be added, removed, or changed
between versions of Python. Use of this module should not be considered to
work across Python VMs or Python releases.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.6: </span>Use 2 bytes for each instruction. Previously the number of bytes varied
by instruction.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.10: </span>The argument of jump, exception handling and loop instructions is now
the instruction offset rather than the byte offset.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.11: </span>Some instructions are accompanied by one or more inline cache entries,
which take the form of <a class="reference internal" href="#opcode-CACHE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CACHE</span></code></a> instructions. These instructions
are hidden by default, but can be shown by passing <code class="docutils literal notranslate"><span class="pre">show_caches=True</span></code> to
any <code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code> utility. Furthermore, the interpreter now adapts the
bytecode to specialize it for different runtime conditions. The
adaptive bytecode can be shown by passing <code class="docutils literal notranslate"><span class="pre">adaptive=True</span></code>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.12: </span>The argument of a jump is the offset of the target instruction relative
to the instruction that appears immediately after the jump instruction's
<a class="reference internal" href="#opcode-CACHE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CACHE</span></code></a> entries.</p>
<p>As a consequence, the presence of the <a class="reference internal" href="#opcode-CACHE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CACHE</span></code></a> instructions is
transparent for forward jumps but needs to be taken into account when
reasoning about backward jumps.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.13: </span>The output shows logical labels rather than instruction offsets
for jump targets and exception handlers. The <code class="docutils literal notranslate"><span class="pre">-O</span></code> command line
option and the <code class="docutils literal notranslate"><span class="pre">show_offsets</span></code> argument were added.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.14: </span>The <a class="reference internal" href="#cmdoption-dis-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> command-line option
and the <code class="docutils literal notranslate"><span class="pre">show_positions</span></code> argument were added.</p>
<p>The <a class="reference internal" href="#cmdoption-dis-S"><code class="xref std std-option docutils literal notranslate"><span class="pre">-S</span></code></a> command-line option is added.</p>
</div>
</div>
<p>Example: Given the function <code class="xref py py-func docutils literal notranslate"><span class="pre">myfunc()</span></code>:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">def</span><span class="w"> </span><span class="nf">myfunc</span><span class="p">(</span><span class="n">alist</span><span class="p">):</span>
<span class="k">return</span> <span class="nb">len</span><span class="p">(</span><span class="n">alist</span><span class="p">)</span>
</pre></div>
</div>
<p>the following command can be used to display the disassembly of
<code class="xref py py-func docutils literal notranslate"><span class="pre">myfunc()</span></code>:</p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">dis</span><span class="o">.</span><span class="n">dis</span><span class="p">(</span><span class="n">myfunc</span><span class="p">)</span>
<span class="go"> 2 RESUME 0</span>
<span class="go"> 3 LOAD_GLOBAL 1 (len + NULL)</span>
<span class="go"> LOAD_FAST_BORROW 0 (alist)</span>
<span class="go"> CALL 1</span>
<span class="go"> RETURN_VALUE</span>
</pre></div>
</div>
<p>(The "2" is a line number).</p>
<section id="command-line-interface">
<span id="dis-cli"></span><h2>Command-line interface<a class="headerlink" href="#command-line-interface" title="Link to this heading">¶</a></h2>
<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code> module can be invoked as a script from the command line:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span>-m<span class="w"> </span>dis<span class="w"> </span><span class="o">[</span>-h<span class="o">]</span><span class="w"> </span><span class="o">[</span>-C<span class="o">]</span><span class="w"> </span><span class="o">[</span>-O<span class="o">]</span><span class="w"> </span><span class="o">[</span>-P<span class="o">]</span><span class="w"> </span><span class="o">[</span>-S<span class="o">]</span><span class="w"> </span><span class="o">[</span>infile<span class="o">]</span>
</pre></div>
</div>
<p>The following options are accepted:</p>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-dis-h">
<span id="cmdoption-dis-help"></span><span class="sig-name descname"><span class="pre">-h</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--help</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-dis-h" title="Link to this definition">¶</a></dt>
<dd><p>Display usage and exit.</p>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-dis-C">
<span id="cmdoption-dis-show-caches"></span><span class="sig-name descname"><span class="pre">-C</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--show-caches</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-dis-C" title="Link to this definition">¶</a></dt>
<dd><p>Show inline caches.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.13.</span></p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-dis-O">
<span id="cmdoption-dis-show-offsets"></span><span class="sig-name descname"><span class="pre">-O</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--show-offsets</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-dis-O" title="Link to this definition">¶</a></dt>
<dd><p>Show offsets of instructions.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.13.</span></p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-dis-P">
<span id="cmdoption-dis-show-positions"></span><span class="sig-name descname"><span class="pre">-P</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--show-positions</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-dis-P" title="Link to this definition">¶</a></dt>
<dd><p>Show positions of instructions in the source code.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.14.</span></p>
</div>
</dd></dl>
<dl class="std option">
<dt class="sig sig-object std" id="cmdoption-dis-S">
<span id="cmdoption-dis-specialized"></span><span class="sig-name descname"><span class="pre">-S</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--specialized</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-dis-S" title="Link to this definition">¶</a></dt>
<dd><p>Show specialized bytecode.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.14.</span></p>
</div>
</dd></dl>
<p>If <code class="file docutils literal notranslate"><span class="pre">infile</span></code> is specified, its disassembled code will be written to stdout.
Otherwise, disassembly is performed on compiled source code received from stdin.</p>
</section>
<section id="bytecode-analysis">
<h2>Bytecode analysis<a class="headerlink" href="#bytecode-analysis" title="Link to this heading">¶</a></h2>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.4.</span></p>
</div>
<p>The bytecode analysis API allows pieces of Python code to be wrapped in a
<a class="reference internal" href="#dis.Bytecode" title="dis.Bytecode"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bytecode</span></code></a> object that provides easy access to details of the compiled
code.</p>
<dl class="py class">
<dt class="sig sig-object py" id="dis.Bytecode">
<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">Bytecode</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">first_line</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">current_offset</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_caches</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">adaptive</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_offsets</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_positions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.Bytecode" title="Link to this definition">¶</a></dt>
<dd><p>Analyse the bytecode corresponding to a function, generator, asynchronous
generator, coroutine, method, string of source code, or a code object (as
returned by <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a>).</p>
<p>This is a convenience wrapper around many of the functions listed below, most
notably <a class="reference internal" href="#dis.get_instructions" title="dis.get_instructions"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_instructions()</span></code></a>, as iterating over a <code class="xref py py-class docutils literal notranslate"><span class="pre">Bytecode</span></code>
instance yields the bytecode operations as <a class="reference internal" href="#dis.Instruction" title="dis.Instruction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Instruction</span></code></a> instances.</p>
<p>If <em>first_line</em> is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, it indicates the line number that should be
reported for the first source line in the disassembled code. Otherwise, the
source line information (if any) is taken directly from the disassembled code
object.</p>
<p>If <em>current_offset</em> is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, it refers to an instruction offset in the
disassembled code. Setting this means <a class="reference internal" href="#dis.Bytecode.dis" title="dis.Bytecode.dis"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dis()</span></code></a> will display a "current
instruction" marker against the specified opcode.</p>
<p>If <em>show_caches</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, <a class="reference internal" href="#dis.Bytecode.dis" title="dis.Bytecode.dis"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dis()</span></code></a> will display inline cache
entries used by the interpreter to specialize the bytecode.</p>
<p>If <em>adaptive</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, <a class="reference internal" href="#dis.Bytecode.dis" title="dis.Bytecode.dis"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dis()</span></code></a> will display specialized bytecode
that may be different from the original bytecode.</p>
<p>If <em>show_offsets</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, <a class="reference internal" href="#dis.Bytecode.dis" title="dis.Bytecode.dis"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dis()</span></code></a> will include instruction
offsets in the output.</p>
<p>If <em>show_positions</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, <a class="reference internal" href="#dis.Bytecode.dis" title="dis.Bytecode.dis"><code class="xref py py-meth docutils literal notranslate"><span class="pre">dis()</span></code></a> will include instruction
source code positions in the output.</p>
<dl class="py method">
<dt class="sig sig-object py" id="dis.Bytecode.from_traceback">
<em class="property"><span class="k"><span class="pre">classmethod</span></span><span class="w"> </span></em><span class="sig-name descname"><span class="pre">from_traceback</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tb</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_caches</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.Bytecode.from_traceback" title="Link to this definition">¶</a></dt>
<dd><p>Construct a <code class="xref py py-class docutils literal notranslate"><span class="pre">Bytecode</span></code> instance from the given traceback, setting
<em>current_offset</em> to the instruction responsible for the exception.</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Bytecode.codeobj">
<span class="sig-name descname"><span class="pre">codeobj</span></span><a class="headerlink" href="#dis.Bytecode.codeobj" title="Link to this definition">¶</a></dt>
<dd><p>The compiled code object.</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Bytecode.first_line">
<span class="sig-name descname"><span class="pre">first_line</span></span><a class="headerlink" href="#dis.Bytecode.first_line" title="Link to this definition">¶</a></dt>
<dd><p>The first source line of the code object (if available)</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="dis.Bytecode.dis">
<span class="sig-name descname"><span class="pre">dis</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#dis.Bytecode.dis" title="Link to this definition">¶</a></dt>
<dd><p>Return a formatted view of the bytecode operations (the same as printed by
<a class="reference internal" href="#dis.dis" title="dis.dis"><code class="xref py py-func docutils literal notranslate"><span class="pre">dis.dis()</span></code></a>, but returned as a multi-line string).</p>
</dd></dl>
<dl class="py method">
<dt class="sig sig-object py" id="dis.Bytecode.info">
<span class="sig-name descname"><span class="pre">info</span></span><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#dis.Bytecode.info" title="Link to this definition">¶</a></dt>
<dd><p>Return a formatted multi-line string with detailed information about the
code object, like <a class="reference internal" href="#dis.code_info" title="dis.code_info"><code class="xref py py-func docutils literal notranslate"><span class="pre">code_info()</span></code></a>.</p>
</dd></dl>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.7: </span>This can now handle coroutine and asynchronous generator objects.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.11: </span>Added the <em>show_caches</em> and <em>adaptive</em> parameters.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.13: </span>Added the <em>show_offsets</em> parameter</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.14: </span>Added the <em>show_positions</em> parameter.</p>
</div>
</dd></dl>
<p>Example:</p>
<div class="highlight-pycon notranslate"><div class="highlight"><pre><span></span><span class="gp">>>> </span><span class="n">bytecode</span> <span class="o">=</span> <span class="n">dis</span><span class="o">.</span><span class="n">Bytecode</span><span class="p">(</span><span class="n">myfunc</span><span class="p">)</span>
<span class="gp">>>> </span><span class="k">for</span> <span class="n">instr</span> <span class="ow">in</span> <span class="n">bytecode</span><span class="p">:</span>
<span class="gp">... </span> <span class="nb">print</span><span class="p">(</span><span class="n">instr</span><span class="o">.</span><span class="n">opname</span><span class="p">)</span>
<span class="gp">...</span>
<span class="go">RESUME</span>
<span class="go">LOAD_GLOBAL</span>
<span class="go">LOAD_FAST_BORROW</span>
<span class="go">CALL</span>
<span class="go">RETURN_VALUE</span>
</pre></div>
</div>
</section>
<section id="analysis-functions">
<h2>Analysis functions<a class="headerlink" href="#analysis-functions" title="Link to this heading">¶</a></h2>
<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code> module also defines the following analysis functions that convert
the input directly to the desired output. They can be useful if only a single
operation is being performed, so the intermediate analysis object isn't useful:</p>
<dl class="py function">
<dt class="sig sig-object py" id="dis.code_info">
<span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">code_info</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.code_info" title="Link to this definition">¶</a></dt>
<dd><p>Return a formatted multi-line string with detailed code object information
for the supplied function, generator, asynchronous generator, coroutine,
method, source code string or code object.</p>
<p>Note that the exact contents of code info strings are highly implementation
dependent and they may change arbitrarily across Python VMs or Python
releases.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.2.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.7: </span>This can now handle coroutine and asynchronous generator objects.</p>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="dis.show_code">
<span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">show_code</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.show_code" title="Link to this definition">¶</a></dt>
<dd><p>Print detailed code object information for the supplied function, method,
source code string or code object to <em>file</em> (or <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code> if <em>file</em>
is not specified).</p>
<p>This is a convenient shorthand for <code class="docutils literal notranslate"><span class="pre">print(code_info(x),</span> <span class="pre">file=file)</span></code>,
intended for interactive exploration at the interpreter prompt.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.2.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.4: </span>Added <em>file</em> parameter.</p>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="dis.dis">
<span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">dis</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">depth</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_caches</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">adaptive</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_offsets</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_positions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.dis" title="Link to this definition">¶</a></dt>
<dd><p>Disassemble the <em>x</em> object. <em>x</em> can denote either a module, a class, a
method, a function, a generator, an asynchronous generator, a coroutine,
a code object, a string of source code or a byte sequence of raw bytecode.
For a module, it disassembles all functions. For a class, it disassembles
all methods (including class and static methods). For a code object or
sequence of raw bytecode, it prints one line per bytecode instruction.
It also recursively disassembles nested code objects. These can include
generator expressions, nested functions, the bodies of nested classes,
and the code objects used for <a class="reference internal" href="../reference/executionmodel.html#annotation-scopes"><span class="std std-ref">annotation scopes</span></a>.
Strings are first compiled to code objects with the <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a>
built-in function before being disassembled. If no object is provided, this
function disassembles the last traceback.</p>
<p>The disassembly is written as text to the supplied <em>file</em> argument if
provided and to <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code> otherwise.</p>
<p>The maximal depth of recursion is limited by <em>depth</em> unless it is <code class="docutils literal notranslate"><span class="pre">None</span></code>.
<code class="docutils literal notranslate"><span class="pre">depth=0</span></code> means no recursion.</p>
<p>If <em>show_caches</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, this function will display inline cache
entries used by the interpreter to specialize the bytecode.</p>
<p>If <em>adaptive</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, this function will display specialized bytecode
that may be different from the original bytecode.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.4: </span>Added <em>file</em> parameter.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.7: </span>Implemented recursive disassembling and added <em>depth</em> parameter.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.7: </span>This can now handle coroutine and asynchronous generator objects.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.11: </span>Added the <em>show_caches</em> and <em>adaptive</em> parameters.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.13: </span>Added the <em>show_offsets</em> parameter.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.14: </span>Added the <em>show_positions</em> parameter.</p>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="dis.distb">
<span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">distb</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">tb</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_caches</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">adaptive</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_offset</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_positions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.distb" title="Link to this definition">¶</a></dt>
<dd><p>Disassemble the top-of-stack function of a traceback, using the last
traceback if none was passed. The instruction causing the exception is
indicated.</p>
<p>The disassembly is written as text to the supplied <em>file</em> argument if
provided and to <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code> otherwise.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.4: </span>Added <em>file</em> parameter.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.11: </span>Added the <em>show_caches</em> and <em>adaptive</em> parameters.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.13: </span>Added the <em>show_offsets</em> parameter.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.14: </span>Added the <em>show_positions</em> parameter.</p>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="dis.disassemble">
<span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">disassemble</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lasti</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_caches</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">adaptive</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_offsets</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_positions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.disassemble" title="Link to this definition">¶</a></dt>
<dt class="sig sig-object py" id="dis.disco">
<span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">disco</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">lasti</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">file</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_caches</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">adaptive</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_offsets</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_positions</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.disco" title="Link to this definition">¶</a></dt>
<dd><p>Disassemble a code object, indicating the last instruction if <em>lasti</em> was
provided. The output is divided in the following columns:</p>
<ol class="arabic simple">
<li><p>the source code location of the instruction. Complete location information
is shown if <em>show_positions</em> is true. Otherwise (the default) only the
line number is displayed.</p></li>
<li><p>the current instruction, indicated as <code class="docutils literal notranslate"><span class="pre">--></span></code>,</p></li>
<li><p>a labelled instruction, indicated with <code class="docutils literal notranslate"><span class="pre">>></span></code>,</p></li>
<li><p>the address of the instruction,</p></li>
<li><p>the operation code name,</p></li>
<li><p>operation parameters, and</p></li>
<li><p>interpretation of the parameters in parentheses.</p></li>
</ol>
<p>The parameter interpretation recognizes local and global variable names,
constant values, branch targets, and compare operators.</p>
<p>The disassembly is written as text to the supplied <em>file</em> argument if
provided and to <code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code> otherwise.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.4: </span>Added <em>file</em> parameter.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.11: </span>Added the <em>show_caches</em> and <em>adaptive</em> parameters.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.13: </span>Added the <em>show_offsets</em> parameter.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.14: </span>Added the <em>show_positions</em> parameter.</p>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="dis.get_instructions">
<span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">get_instructions</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">x</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">first_line</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">show_caches</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">adaptive</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.get_instructions" title="Link to this definition">¶</a></dt>
<dd><p>Return an iterator over the instructions in the supplied function, method,
source code string or code object.</p>
<p>The iterator generates a series of <a class="reference internal" href="#dis.Instruction" title="dis.Instruction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Instruction</span></code></a> named tuples giving
the details of each operation in the supplied code.</p>
<p>If <em>first_line</em> is not <code class="docutils literal notranslate"><span class="pre">None</span></code>, it indicates the line number that should be
reported for the first source line in the disassembled code. Otherwise, the
source line information (if any) is taken directly from the disassembled code
object.</p>
<p>The <em>adaptive</em> parameter works as it does in <a class="reference internal" href="#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-func docutils literal notranslate"><span class="pre">dis()</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.4.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.11: </span>Added the <em>show_caches</em> and <em>adaptive</em> parameters.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.13: </span>The <em>show_caches</em> parameter is deprecated and has no effect. The iterator
generates the <a class="reference internal" href="#dis.Instruction" title="dis.Instruction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Instruction</span></code></a> instances with the <em>cache_info</em>
field populated (regardless of the value of <em>show_caches</em>) and it no longer
generates separate items for the cache entries.</p>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="dis.findlinestarts">
<span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">findlinestarts</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.findlinestarts" title="Link to this definition">¶</a></dt>
<dd><p>This generator function uses the <a class="reference internal" href="../reference/datamodel.html#codeobject.co_lines" title="codeobject.co_lines"><code class="xref py py-meth docutils literal notranslate"><span class="pre">co_lines()</span></code></a> method
of the <a class="reference internal" href="../reference/datamodel.html#code-objects"><span class="std std-ref">code object</span></a> <em>code</em> to find the offsets which
are starts of
lines in the source code. They are generated as <code class="docutils literal notranslate"><span class="pre">(offset,</span> <span class="pre">lineno)</span></code> pairs.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.6: </span>Line numbers can be decreasing. Before, they were always increasing.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.10: </span>The <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0626/"><strong>PEP 626</strong></a> <a class="reference internal" href="../reference/datamodel.html#codeobject.co_lines" title="codeobject.co_lines"><code class="xref py py-meth docutils literal notranslate"><span class="pre">co_lines()</span></code></a> method is used instead of the
<a class="reference internal" href="../reference/datamodel.html#codeobject.co_firstlineno" title="codeobject.co_firstlineno"><code class="xref py py-attr docutils literal notranslate"><span class="pre">co_firstlineno</span></code></a> and <a class="reference internal" href="../reference/datamodel.html#codeobject.co_lnotab" title="codeobject.co_lnotab"><code class="xref py py-attr docutils literal notranslate"><span class="pre">co_lnotab</span></code></a>
attributes of the <a class="reference internal" href="../reference/datamodel.html#code-objects"><span class="std std-ref">code object</span></a>.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.13: </span>Line numbers can be <code class="docutils literal notranslate"><span class="pre">None</span></code> for bytecode that does not map to source lines.</p>
</div>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="dis.findlabels">
<span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">findlabels</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">code</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.findlabels" title="Link to this definition">¶</a></dt>
<dd><p>Detect all offsets in the raw compiled bytecode string <em>code</em> which are jump targets, and
return a list of these offsets.</p>
</dd></dl>
<dl class="py function">
<dt class="sig sig-object py" id="dis.stack_effect">
<span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">stack_effect</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">opcode</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">oparg</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="keyword-only-separator o"><abbr title="Keyword-only parameters separator (PEP 3102)"><span class="pre">*</span></abbr></span></em>, <em class="sig-param"><span class="n"><span class="pre">jump</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#dis.stack_effect" title="Link to this definition">¶</a></dt>
<dd><p>Compute the stack effect of <em>opcode</em> with argument <em>oparg</em>.</p>
<p>If the code has a jump target and <em>jump</em> is <code class="docutils literal notranslate"><span class="pre">True</span></code>, <code class="xref py py-func docutils literal notranslate"><span class="pre">stack_effect()</span></code>
will return the stack effect of jumping. If <em>jump</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code>,
it will return the stack effect of not jumping. And if <em>jump</em> is
<code class="docutils literal notranslate"><span class="pre">None</span></code> (default), it will return the maximal stack effect of both cases.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.4.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.8: </span>Added <em>jump</em> parameter.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.13: </span>If <code class="docutils literal notranslate"><span class="pre">oparg</span></code> is omitted (or <code class="docutils literal notranslate"><span class="pre">None</span></code>), the stack effect is now returned
for <code class="docutils literal notranslate"><span class="pre">oparg=0</span></code>. Previously this was an error for opcodes that use their
arg. It is also no longer an error to pass an integer <code class="docutils literal notranslate"><span class="pre">oparg</span></code> when
the <code class="docutils literal notranslate"><span class="pre">opcode</span></code> does not use it; the <code class="docutils literal notranslate"><span class="pre">oparg</span></code> in this case is ignored.</p>
</div>
</dd></dl>
</section>
<section id="python-bytecode-instructions">
<span id="bytecodes"></span><h2>Python Bytecode Instructions<a class="headerlink" href="#python-bytecode-instructions" title="Link to this heading">¶</a></h2>
<p>The <a class="reference internal" href="#dis.get_instructions" title="dis.get_instructions"><code class="xref py py-func docutils literal notranslate"><span class="pre">get_instructions()</span></code></a> function and <a class="reference internal" href="#dis.Bytecode" title="dis.Bytecode"><code class="xref py py-class docutils literal notranslate"><span class="pre">Bytecode</span></code></a> class provide
details of bytecode instructions as <a class="reference internal" href="#dis.Instruction" title="dis.Instruction"><code class="xref py py-class docutils literal notranslate"><span class="pre">Instruction</span></code></a> instances:</p>
<dl class="py class">
<dt class="sig sig-object py" id="dis.Instruction">
<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">Instruction</span></span><a class="headerlink" href="#dis.Instruction" title="Link to this definition">¶</a></dt>
<dd><p>Details for a bytecode operation</p>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.opcode">
<span class="sig-name descname"><span class="pre">opcode</span></span><a class="headerlink" href="#dis.Instruction.opcode" title="Link to this definition">¶</a></dt>
<dd><p>numeric code for operation, corresponding to the opcode values listed
below and the bytecode values in the <a class="reference internal" href="#opcode-collections"><span class="std std-ref">Opcode collections</span></a>.</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.opname">
<span class="sig-name descname"><span class="pre">opname</span></span><a class="headerlink" href="#dis.Instruction.opname" title="Link to this definition">¶</a></dt>
<dd><p>human readable name for operation</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.baseopcode">
<span class="sig-name descname"><span class="pre">baseopcode</span></span><a class="headerlink" href="#dis.Instruction.baseopcode" title="Link to this definition">¶</a></dt>
<dd><p>numeric code for the base operation if operation is specialized;
otherwise equal to <a class="reference internal" href="#dis.Instruction.opcode" title="dis.Instruction.opcode"><code class="xref py py-data docutils literal notranslate"><span class="pre">opcode</span></code></a></p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.baseopname">
<span class="sig-name descname"><span class="pre">baseopname</span></span><a class="headerlink" href="#dis.Instruction.baseopname" title="Link to this definition">¶</a></dt>
<dd><p>human readable name for the base operation if operation is specialized;
otherwise equal to <a class="reference internal" href="#dis.opname" title="dis.opname"><code class="xref py py-data docutils literal notranslate"><span class="pre">opname</span></code></a></p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.arg">
<span class="sig-name descname"><span class="pre">arg</span></span><a class="headerlink" href="#dis.Instruction.arg" title="Link to this definition">¶</a></dt>
<dd><p>numeric argument to operation (if any), otherwise <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.oparg">
<span class="sig-name descname"><span class="pre">oparg</span></span><a class="headerlink" href="#dis.Instruction.oparg" title="Link to this definition">¶</a></dt>
<dd><p>alias for <a class="reference internal" href="#dis.Instruction.arg" title="dis.Instruction.arg"><code class="xref py py-data docutils literal notranslate"><span class="pre">arg</span></code></a></p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.argval">
<span class="sig-name descname"><span class="pre">argval</span></span><a class="headerlink" href="#dis.Instruction.argval" title="Link to this definition">¶</a></dt>
<dd><p>resolved arg value (if any), otherwise <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.argrepr">
<span class="sig-name descname"><span class="pre">argrepr</span></span><a class="headerlink" href="#dis.Instruction.argrepr" title="Link to this definition">¶</a></dt>
<dd><p>human readable description of operation argument (if any),
otherwise an empty string.</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.offset">
<span class="sig-name descname"><span class="pre">offset</span></span><a class="headerlink" href="#dis.Instruction.offset" title="Link to this definition">¶</a></dt>
<dd><p>start index of operation within bytecode sequence</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.start_offset">
<span class="sig-name descname"><span class="pre">start_offset</span></span><a class="headerlink" href="#dis.Instruction.start_offset" title="Link to this definition">¶</a></dt>
<dd><p>start index of operation within bytecode sequence, including prefixed
<code class="docutils literal notranslate"><span class="pre">EXTENDED_ARG</span></code> operations if present; otherwise equal to <a class="reference internal" href="#dis.Instruction.offset" title="dis.Instruction.offset"><code class="xref py py-data docutils literal notranslate"><span class="pre">offset</span></code></a></p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.cache_offset">
<span class="sig-name descname"><span class="pre">cache_offset</span></span><a class="headerlink" href="#dis.Instruction.cache_offset" title="Link to this definition">¶</a></dt>
<dd><p>start index of the cache entries following the operation</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.end_offset">
<span class="sig-name descname"><span class="pre">end_offset</span></span><a class="headerlink" href="#dis.Instruction.end_offset" title="Link to this definition">¶</a></dt>
<dd><p>end index of the cache entries following the operation</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.starts_line">
<span class="sig-name descname"><span class="pre">starts_line</span></span><a class="headerlink" href="#dis.Instruction.starts_line" title="Link to this definition">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if this opcode starts a source line, otherwise <code class="docutils literal notranslate"><span class="pre">False</span></code></p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.line_number">
<span class="sig-name descname"><span class="pre">line_number</span></span><a class="headerlink" href="#dis.Instruction.line_number" title="Link to this definition">¶</a></dt>
<dd><p>source line number associated with this opcode (if any), otherwise <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.is_jump_target">
<span class="sig-name descname"><span class="pre">is_jump_target</span></span><a class="headerlink" href="#dis.Instruction.is_jump_target" title="Link to this definition">¶</a></dt>
<dd><p><code class="docutils literal notranslate"><span class="pre">True</span></code> if other code jumps to here, otherwise <code class="docutils literal notranslate"><span class="pre">False</span></code></p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.jump_target">
<span class="sig-name descname"><span class="pre">jump_target</span></span><a class="headerlink" href="#dis.Instruction.jump_target" title="Link to this definition">¶</a></dt>
<dd><p>bytecode index of the jump target if this is a jump operation,
otherwise <code class="docutils literal notranslate"><span class="pre">None</span></code></p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.positions">
<span class="sig-name descname"><span class="pre">positions</span></span><a class="headerlink" href="#dis.Instruction.positions" title="Link to this definition">¶</a></dt>
<dd><p><a class="reference internal" href="#dis.Positions" title="dis.Positions"><code class="xref py py-class docutils literal notranslate"><span class="pre">dis.Positions</span></code></a> object holding the
start and end locations that are covered by this instruction.</p>
</dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Instruction.cache_info">
<span class="sig-name descname"><span class="pre">cache_info</span></span><a class="headerlink" href="#dis.Instruction.cache_info" title="Link to this definition">¶</a></dt>
<dd><p>Information about the cache entries of this instruction, as
triplets of the form <code class="docutils literal notranslate"><span class="pre">(name,</span> <span class="pre">size,</span> <span class="pre">data)</span></code>, where the <code class="docutils literal notranslate"><span class="pre">name</span></code>
and <code class="docutils literal notranslate"><span class="pre">size</span></code> describe the cache format and data is the contents
of the cache. <code class="docutils literal notranslate"><span class="pre">cache_info</span></code> is <code class="docutils literal notranslate"><span class="pre">None</span></code> if the instruction does not have
caches.</p>
</dd></dl>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.4.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.11: </span>Field <code class="docutils literal notranslate"><span class="pre">positions</span></code> is added.</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.13: </span>Changed field <code class="docutils literal notranslate"><span class="pre">starts_line</span></code>.</p>
<p>Added fields <code class="docutils literal notranslate"><span class="pre">start_offset</span></code>, <code class="docutils literal notranslate"><span class="pre">cache_offset</span></code>, <code class="docutils literal notranslate"><span class="pre">end_offset</span></code>,
<code class="docutils literal notranslate"><span class="pre">baseopname</span></code>, <code class="docutils literal notranslate"><span class="pre">baseopcode</span></code>, <code class="docutils literal notranslate"><span class="pre">jump_target</span></code>, <code class="docutils literal notranslate"><span class="pre">oparg</span></code>,
<code class="docutils literal notranslate"><span class="pre">line_number</span></code> and <code class="docutils literal notranslate"><span class="pre">cache_info</span></code>.</p>
</div>
</dd></dl>
<dl class="py class">
<dt class="sig sig-object py" id="dis.Positions">
<em class="property"><span class="k"><span class="pre">class</span></span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">dis.</span></span><span class="sig-name descname"><span class="pre">Positions</span></span><a class="headerlink" href="#dis.Positions" title="Link to this definition">¶</a></dt>
<dd><p>In case the information is not available, some fields might be <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Positions.lineno">
<span class="sig-name descname"><span class="pre">lineno</span></span><a class="headerlink" href="#dis.Positions.lineno" title="Link to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Positions.end_lineno">
<span class="sig-name descname"><span class="pre">end_lineno</span></span><a class="headerlink" href="#dis.Positions.end_lineno" title="Link to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Positions.col_offset">
<span class="sig-name descname"><span class="pre">col_offset</span></span><a class="headerlink" href="#dis.Positions.col_offset" title="Link to this definition">¶</a></dt>
<dd></dd></dl>
<dl class="py data">
<dt class="sig sig-object py" id="dis.Positions.end_col_offset">
<span class="sig-name descname"><span class="pre">end_col_offset</span></span><a class="headerlink" href="#dis.Positions.end_col_offset" title="Link to this definition">¶</a></dt>
<dd></dd></dl>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</dd></dl>
<p>The Python compiler currently generates the following bytecode instructions.</p>
<p><strong>General instructions</strong></p>
<p>In the following, We will refer to the interpreter stack as <code class="docutils literal notranslate"><span class="pre">STACK</span></code> and describe
operations on it as if it was a Python list. The top of the stack corresponds to
<code class="docutils literal notranslate"><span class="pre">STACK[-1]</span></code> in this language.</p>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-NOP">
<span class="sig-name descname"><span class="pre">NOP</span></span><a class="headerlink" href="#opcode-NOP" title="Link to this definition">¶</a></dt>
<dd><p>Do nothing code. Used as a placeholder by the bytecode optimizer, and to
generate line tracing events.</p>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-NOT_TAKEN">
<span class="sig-name descname"><span class="pre">NOT_TAKEN</span></span><a class="headerlink" href="#opcode-NOT_TAKEN" title="Link to this definition">¶</a></dt>
<dd><p>Do nothing code.
Used by the interpreter to record <a class="reference internal" href="sys.monitoring.html#monitoring-event-BRANCH_LEFT"><code class="xref std std-monitoring-event docutils literal notranslate"><span class="pre">BRANCH_LEFT</span></code></a>
and <a class="reference internal" href="sys.monitoring.html#monitoring-event-BRANCH_RIGHT"><code class="xref std std-monitoring-event docutils literal notranslate"><span class="pre">BRANCH_RIGHT</span></code></a> events for <a class="reference internal" href="sys.monitoring.html#module-sys.monitoring" title="sys.monitoring: Access and control event monitoring"><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys.monitoring</span></code></a>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.14.</span></p>
</div>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-POP_ITER">
<span class="sig-name descname"><span class="pre">POP_ITER</span></span><a class="headerlink" href="#opcode-POP_ITER" title="Link to this definition">¶</a></dt>
<dd><p>Removes the iterator from the top of the stack.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.14.</span></p>
</div>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-POP_TOP">
<span class="sig-name descname"><span class="pre">POP_TOP</span></span><a class="headerlink" href="#opcode-POP_TOP" title="Link to this definition">¶</a></dt>
<dd><p>Removes the top-of-stack item:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">STACK</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
</pre></div>
</div>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-END_FOR">
<span class="sig-name descname"><span class="pre">END_FOR</span></span><a class="headerlink" href="#opcode-END_FOR" title="Link to this definition">¶</a></dt>
<dd><p>Removes the top-of-stack item.
Equivalent to <code class="docutils literal notranslate"><span class="pre">POP_TOP</span></code>.
Used to clean up at the end of loops, hence the name.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.12.</span></p>
</div>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-END_SEND">
<span class="sig-name descname"><span class="pre">END_SEND</span></span><a class="headerlink" href="#opcode-END_SEND" title="Link to this definition">¶</a></dt>
<dd><p>Implements <code class="docutils literal notranslate"><span class="pre">del</span> <span class="pre">STACK[-2]</span></code>.
Used to clean up when a generator exits.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.12.</span></p>
</div>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-COPY">
<span class="sig-name descname"><span class="pre">COPY</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">i</span></em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-COPY" title="Link to this definition">¶</a></dt>
<dd><p>Push the i-th item to the top of the stack without removing it from its original
location:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="k">assert</span> <span class="n">i</span> <span class="o">></span> <span class="mi">0</span>
<span class="n">STACK</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">STACK</span><span class="p">[</span><span class="o">-</span><span class="n">i</span><span class="p">])</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-SWAP">
<span class="sig-name descname"><span class="pre">SWAP</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">i</span></em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-SWAP" title="Link to this definition">¶</a></dt>
<dd><p>Swap the top of the stack with the i-th element:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">STACK</span><span class="p">[</span><span class="o">-</span><span class="n">i</span><span class="p">],</span> <span class="n">STACK</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span> <span class="o">=</span> <span class="n">STACK</span><span class="p">[</span><span class="o">-</span><span class="mi">1</span><span class="p">],</span> <span class="n">STACK</span><span class="p">[</span><span class="o">-</span><span class="n">i</span><span class="p">]</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-CACHE">
<span class="sig-name descname"><span class="pre">CACHE</span></span><a class="headerlink" href="#opcode-CACHE" title="Link to this definition">¶</a></dt>
<dd><p>Rather than being an actual instruction, this opcode is used to mark extra
space for the interpreter to cache useful data directly in the bytecode
itself. It is automatically hidden by all <code class="docutils literal notranslate"><span class="pre">dis</span></code> utilities, but can be
viewed with <code class="docutils literal notranslate"><span class="pre">show_caches=True</span></code>.</p>
<p>Logically, this space is part of the preceding instruction. Many opcodes
expect to be followed by an exact number of caches, and will instruct the
interpreter to skip over them at runtime.</p>
<p>Populated caches can look like arbitrary instructions, so great care should
be taken when reading or modifying raw, adaptive bytecode containing
quickened data.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
</dd></dl>
<p><strong>Unary operations</strong></p>
<p>Unary operations take the top of the stack, apply the operation, and push the
result back on the stack.</p>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-UNARY_NEGATIVE">
<span class="sig-name descname"><span class="pre">UNARY_NEGATIVE</span></span><a class="headerlink" href="#opcode-UNARY_NEGATIVE" title="Link to this definition">¶</a></dt>
<dd><p>Implements <code class="docutils literal notranslate"><span class="pre">STACK[-1]</span> <span class="pre">=</span> <span class="pre">-STACK[-1]</span></code>.</p>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-UNARY_NOT">
<span class="sig-name descname"><span class="pre">UNARY_NOT</span></span><a class="headerlink" href="#opcode-UNARY_NOT" title="Link to this definition">¶</a></dt>
<dd><p>Implements <code class="docutils literal notranslate"><span class="pre">STACK[-1]</span> <span class="pre">=</span> <span class="pre">not</span> <span class="pre">STACK[-1]</span></code>.</p>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.13: </span>This instruction now requires an exact <a class="reference internal" href="functions.html#bool" title="bool"><code class="xref py py-class docutils literal notranslate"><span class="pre">bool</span></code></a> operand.</p>
</div>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-UNARY_INVERT">
<span class="sig-name descname"><span class="pre">UNARY_INVERT</span></span><a class="headerlink" href="#opcode-UNARY_INVERT" title="Link to this definition">¶</a></dt>
<dd><p>Implements <code class="docutils literal notranslate"><span class="pre">STACK[-1]</span> <span class="pre">=</span> <span class="pre">~STACK[-1]</span></code>.</p>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-GET_ITER">
<span class="sig-name descname"><span class="pre">GET_ITER</span></span><a class="headerlink" href="#opcode-GET_ITER" title="Link to this definition">¶</a></dt>
<dd><p>Implements <code class="docutils literal notranslate"><span class="pre">STACK[-1]</span> <span class="pre">=</span> <span class="pre">iter(STACK[-1])</span></code>.</p>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-GET_YIELD_FROM_ITER">
<span class="sig-name descname"><span class="pre">GET_YIELD_FROM_ITER</span></span><a class="headerlink" href="#opcode-GET_YIELD_FROM_ITER" title="Link to this definition">¶</a></dt>
<dd><p>If <code class="docutils literal notranslate"><span class="pre">STACK[-1]</span></code> is a <a class="reference internal" href="../glossary.html#term-generator-iterator"><span class="xref std std-term">generator iterator</span></a> or <a class="reference internal" href="../glossary.html#term-coroutine"><span class="xref std std-term">coroutine</span></a> object
it is left as is. Otherwise, implements <code class="docutils literal notranslate"><span class="pre">STACK[-1]</span> <span class="pre">=</span> <span class="pre">iter(STACK[-1])</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.5.</span></p>
</div>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-TO_BOOL">
<span class="sig-name descname"><span class="pre">TO_BOOL</span></span><a class="headerlink" href="#opcode-TO_BOOL" title="Link to this definition">¶</a></dt>
<dd><p>Implements <code class="docutils literal notranslate"><span class="pre">STACK[-1]</span> <span class="pre">=</span> <span class="pre">bool(STACK[-1])</span></code>.</p>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.13.</span></p>
</div>
</dd></dl>
<p><strong>Binary and in-place operations</strong></p>
<p>Binary operations remove the top two items from the stack (<code class="docutils literal notranslate"><span class="pre">STACK[-1]</span></code> and
<code class="docutils literal notranslate"><span class="pre">STACK[-2]</span></code>). They perform the operation, then put the result back on the stack.</p>
<p>In-place operations are like binary operations, but the operation is done in-place
when <code class="docutils literal notranslate"><span class="pre">STACK[-2]</span></code> supports it, and the resulting <code class="docutils literal notranslate"><span class="pre">STACK[-1]</span></code> may be (but does
not have to be) the original <code class="docutils literal notranslate"><span class="pre">STACK[-2]</span></code>.</p>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-BINARY_OP">
<span class="sig-name descname"><span class="pre">BINARY_OP</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="pre">op</span></em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BINARY_OP" title="Link to this definition">¶</a></dt>
<dd><p>Implements the binary and in-place operators (depending on the value of
<em>op</em>):</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">rhs</span> <span class="o">=</span> <span class="n">STACK</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
<span class="n">lhs</span> <span class="o">=</span> <span class="n">STACK</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
<span class="n">STACK</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">lhs</span> <span class="n">op</span> <span class="n">rhs</span><span class="p">)</span>
</pre></div>
</div>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.11.</span></p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">تغییر داده شده در نسخه 3.14: </span>With oparg :<code class="docutils literal notranslate"><span class="pre">NB_SUBSCR</span></code>, implements binary subscript (replaces opcode <code class="docutils literal notranslate"><span class="pre">BINARY_SUBSCR</span></code>)</p>
</div>
</dd></dl>
<dl class="std opcode">
<dt class="sig sig-object std" id="opcode-STORE_SUBSCR">
<span class="sig-name descname"><span class="pre">STORE_SUBSCR</span></span><a class="headerlink" href="#opcode-STORE_SUBSCR" title="Link to this definition">¶</a></dt>
<dd><p>Implements:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">key</span> <span class="o">=</span> <span class="n">STACK</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>
<span class="n">container</span> <span class="o">=</span> <span class="n">STACK</span><span class="o">.</span><span class="n">pop</span><span class="p">()</span>