/
usr
/
share
/
doc
/
python3-docs
/
html
/
library
/
/usr/share/doc/python3-docs/html/library
mkdir
upload
Name
Size
Mode
Actions
2to3.html
61709
0644
edit
dl
rm
abc.html
41394
0644
edit
dl
rm
aifc.html
28114
0644
edit
dl
rm
allos.html
32236
0644
edit
dl
rm
archiving.html
11992
0644
edit
dl
rm
argparse.html
274984
0644
edit
dl
rm
array.html
33547
0644
edit
dl
rm
ast.html
39595
0644
edit
dl
rm
asynchat.html
32546
0644
edit
dl
rm
asyncio-dev.html
51869
0644
edit
dl
rm
asyncio-eventloop.html
111215
0644
edit
dl
rm
asyncio-eventloops.html
33026
0644
edit
dl
rm
asyncio-protocol.html
87431
0644
edit
dl
rm
asyncio-queue.html
23957
0644
edit
dl
rm
asyncio-stream.html
61005
0644
edit
dl
rm
asyncio-subprocess.html
58015
0644
edit
dl
rm
asyncio-sync.html
35678
0644
edit
dl
rm
asyncio-task.html
83968
0644
edit
dl
rm
asyncio.html
28026
0644
edit
dl
rm
asyncore.html
42706
0644
edit
dl
rm
atexit.html
18433
0644
edit
dl
rm
audioop.html
35442
0644
edit
dl
rm
base64.html
36454
0644
edit
dl
rm
bdb.html
43423
0644
edit
dl
rm
binary.html
12723
0644
edit
dl
rm
binascii.html
24745
0644
edit
dl
rm
binhex.html
11669
0644
edit
dl
rm
bisect.html
25602
0644
edit
dl
rm
builtins.html
11604
0644
edit
dl
rm
bz2.html
33358
0644
edit
dl
rm
calendar.html
39539
0644
edit
dl
rm
cgi.html
55881
0644
edit
dl
rm
cgitb.html
12765
0644
edit
dl
rm
chunk.html
16872
0644
edit
dl
rm
cmath.html
34171
0644
edit
dl
rm
cmd.html
43811
0644
edit
dl
rm
code.html
27886
0644
edit
dl
rm
codecs.html
134071
0644
edit
dl
rm
codeop.html
14304
0644
edit
dl
rm
collections.abc.html
60912
0644
edit
dl
rm
collections.html
154946
0644
edit
dl
rm
colorsys.html
12627
0644
edit
dl
rm
compileall.html
28263
0644
edit
dl
rm
concurrency.html
21203
0644
edit
dl
rm
concurrent.futures.html
60660
0644
edit
dl
rm
concurrent.html
7959
0644
edit
dl
rm
configparser.html
141052
0644
edit
dl
rm
constants.html
17500
0644
edit
dl
rm
contextlib.html
88801
0644
edit
dl
rm
copy.html
13841
0644
edit
dl
rm
copyreg.html
14725
0644
edit
dl
rm
crypt.html
20331
0644
edit
dl
rm
crypto.html
10914
0644
edit
dl
rm
csv.html
69043
0644
edit
dl
rm
ctypes.html
264529
0644
edit
dl
rm
curses.ascii.html
25197
0644
edit
dl
rm
curses.html
175551
0644
edit
dl
rm
curses.panel.html
16706
0644
edit
dl
rm
custominterp.html
8734
0644
edit
dl
rm
datatypes.html
23950
0644
edit
dl
rm
datetime.html
306435
0644
edit
dl
rm
dbm.html
43119
0644
edit
dl
rm
debug.html
13983
0644
edit
dl
rm
decimal.html
233486
0644
edit
dl
rm
development.html
25123
0644
edit
dl
rm
difflib.html
96156
0644
edit
dl
rm
dis.html
106191
0644
edit
dl
rm
distribution.html
10506
0644
edit
dl
rm
distutils.html
10884
0644
edit
dl
rm
doctest.html
179752
0644
edit
dl
rm
dummy_threading.html
9316
0644
edit
dl
rm
email.charset.html
26431
0644
edit
dl
rm
email.compat32-message.html
86150
0644
edit
dl
rm
email.contentmanager.html
30028
0644
edit
dl
rm
email.encoders.html
14250
0644
edit
dl
rm
email.errors.html
19704
0644
edit
dl
rm
email.examples.html
57872
0644
edit
dl
rm
email.generator.html
41798
0644
edit
dl
rm
email.header.html
31219
0644
edit
dl
rm
email.headerregistry.html
57670
0644
edit
dl
rm
email.html
27741
0644
edit
dl
rm
email.iterators.html
13532
0644
edit
dl
rm
email.message.html
87210
0644
edit
dl
rm
email.mime.html
36081
0644
edit
dl
rm
email.parser.html
47430
0644
edit
dl
rm
email.policy.html
75241
0644
edit
dl
rm
email.util.html
33853
0644
edit
dl
rm
ensurepip.html
18700
0644
edit
dl
rm
enum.html
133949
0644
edit
dl
rm
errno.html
41331
0644
edit
dl
rm
exceptions.html
85151
0644
edit
dl
rm
faulthandler.html
23396
0644
edit
dl
rm
fcntl.html
27321
0644
edit
dl
rm
filecmp.html
25036
0644
edit
dl
rm
fileformats.html
11129
0644
edit
dl
rm
fileinput.html
30030
0644
edit
dl
rm
filesys.html
13418
0644
edit
dl
rm
fnmatch.html
16987
0644
edit
dl
rm
formatter.html
37666
0644
edit
dl
rm
fpectl.html
17538
0644
edit
dl
rm
fractions.html
29918
0644
edit
dl
rm
frameworks.html
13471
0644
edit
dl
rm
ftplib.html
54429
0644
edit
dl
rm
functional.html
9002
0644
edit
dl
rm
functions.html
201486
0644
edit
dl
rm
functools.html
64951
0644
edit
dl
rm
gc.html
29524
0644
edit
dl
rm
getopt.html
25353
0644
edit
dl
rm
getpass.html
12061
0644
edit
dl
rm
gettext.html
76641
0644
edit
dl
rm
glob.html
18432
0644
edit
dl
rm
grp.html
12383
0644
edit
dl
rm
gzip.html
32669
0644
edit
dl
rm
hashlib.html
79554
0644
edit
dl
rm
heapq.html
35529
0644
edit
dl
rm
hmac.html
17827
0644
edit
dl
rm
html.entities.html
11361
0644
edit
dl
rm
html.html
11108
0644
edit
dl
rm
html.parser.html
41842
0644
edit
dl
rm
http.client.html
65250
0644
edit
dl
rm
http.cookiejar.html
96195
0644
edit
dl
rm
http.cookies.html
39329
0644
edit
dl
rm
http.html
37602
0644
edit
dl
rm
http.server.html
58191
0644
edit
dl
rm
i18n.html
10464
0644
edit
dl
rm
idle.html
48412
0644
edit
dl
rm
imaplib.html
67339
0644
edit
dl
rm
imghdr.html
13456
0644
edit
dl
rm
imp.html
48153
0644
edit
dl
rm
importlib.html
173109
0644
edit
dl
rm
index.html
67768
0644
edit
dl
rm
inspect.html
130355
0644
edit
dl
rm
internet.html
31087
0644
edit
dl
rm
intro.html
9904
0644
edit
dl
rm
io.html
122685
0644
edit
dl
rm
ipaddress.html
105873
0644
edit
dl
rm
ipc.html
33743
0644
edit
dl
rm
itertools.html
132824
0644
edit
dl
rm
json.html
81078
0644
edit
dl
rm
keyword.html
8918
0644
edit
dl
rm
language.html
13648
0644
edit
dl
rm
linecache.html
13492
0644
edit
dl
rm
locale.html
61540
0644
edit
dl
rm
logging.config.html
85489
0644
edit
dl
rm
logging.handlers.html
112397
0644
edit
dl
rm
logging.html
134850
0644
edit
dl
rm
lzma.html
56484
0644
edit
dl
rm
macpath.html
9257
0644
edit
dl
rm
mailbox.html
157315
0644
edit
dl
rm
mailcap.html
14676
0644
edit
dl
rm
markup.html
19356
0644
edit
dl
rm
marshal.html
18317
0644
edit
dl
rm
math.html
53661
0644
edit
dl
rm
mimetypes.html
31410
0644
edit
dl
rm
misc.html
8123
0644
edit
dl
rm
mm.html
10022
0644
edit
dl
rm
mmap.html
34294
0644
edit
dl
rm
modulefinder.html
18559
0644
edit
dl
rm
modules.html
10914
0644
edit
dl
rm
msilib.html
57205
0644
edit
dl
rm
msvcrt.html
21989
0644
edit
dl
rm
multiprocessing.html
365487
0644
edit
dl
rm
netdata.html
17470
0644
edit
dl
rm
netrc.html
14568
0644
edit
dl
rm
nis.html
11659
0644
edit
dl
rm
nntplib.html
69601
0644
edit
dl
rm
numbers.html
41432
0644
edit
dl
rm
numeric.html
15535
0644
edit
dl
rm
operator.html
81460
0644
edit
dl
rm
optparse.html
249942
0644
edit
dl
rm
os.html
398039
0644
edit
dl
rm
os.path.html
53818
0644
edit
dl
rm
ossaudiodev.html
47947
0644
edit
dl
rm
othergui.html
10256
0644
edit
dl
rm
parser.html
42408
0644
edit
dl
rm
pathlib.html
116726
0644
edit
dl
rm
pdb.html
52661
0644
edit
dl
rm
persistence.html
15281
0644
edit
dl
rm
pickle.html
115052
0644
edit
dl
rm
pickletools.html
17094
0644
edit
dl
rm
pipes.html
15991
0644
edit
dl
rm
pkgutil.html
31878
0644
edit
dl
rm
platform.html
33728
0644
edit
dl
rm
plistlib.html
29290
0644
edit
dl
rm
poplib.html
30940
0644
edit
dl
rm
posix.html
17608
0644
edit
dl
rm
pprint.html
41969
0644
edit
dl
rm
profile.html
71848
0644
edit
dl
rm
pty.html
17594
0644
edit
dl
rm
pwd.html
13098
0644
edit
dl
rm
pyclbr.html
16520
0644
edit
dl
rm
pydoc.html
15991
0644
edit
dl
rm
pyexpat.html
88938
0644
edit
dl
rm
python.html
17133
0644
edit
dl
rm
py_compile.html
15508
0644
edit
dl
rm
queue.html
28199
0644
edit
dl
rm
quopri.html
13858
0644
edit
dl
rm
random.html
60646
0644
edit
dl
rm
re.html
191176
0644
edit
dl
rm
readline.html
42133
0644
edit
dl
rm
reprlib.html
24964
0644
edit
dl
rm
resource.html
36552
0644
edit
dl
rm
rlcompleter.html
14392
0644
edit
dl
rm
runpy.html
26607
0644
edit
dl
rm
sched.html
20034
0644
edit
dl
rm
secrets.html
24734
0644
edit
dl
rm
select.html
62819
0644
edit
dl
rm
selectors.html
35845
0644
edit
dl
rm
shelve.html
28777
0644
edit
dl
rm
shlex.html
48979
0644
edit
dl
rm
shutil.html
74207
0644
edit
dl
rm
signal.html
55064
0644
edit
dl
rm
site.html
32242
0644
edit
dl
rm
smtpd.html
35892
0644
edit
dl
rm
smtplib.html
68433
0644
edit
dl
rm
sndhdr.html
12439
0644
edit
dl
rm
socket.html
196077
0644
edit
dl
rm
socketserver.html
81918
0644
edit
dl
rm
spwd.html
12328
0644
edit
dl
rm
sqlite3.html
161872
0644
edit
dl
rm
ssl.html
266327
0644
edit
dl
rm
stat.html
44722
0644
edit
dl
rm
statistics.html
50050
0644
edit
dl
rm
stdtypes.html
465658
0644
edit
dl
rm
string.html
95262
0644
edit
dl
rm
stringprep.html
18654
0644
edit
dl
rm
struct.html
51100
0644
edit
dl
rm
subprocess.html
141926
0644
edit
dl
rm
sunau.html
31757
0644
edit
dl
rm
superseded.html
13781
0644
edit
dl
rm
symbol.html
8848
0644
edit
dl
rm
symtable.html
26112
0644
edit
dl
rm
sys.html
141670
0644
edit
dl
rm
sysconfig.html
30259
0644
edit
dl
rm
syslog.html
21026
0644
edit
dl
rm
tabnanny.html
12269
0644
edit
dl
rm
tarfile.html
96758
0644
edit
dl
rm
telnetlib.html
30409
0644
edit
dl
rm
tempfile.html
41394
0644
edit
dl
rm
termios.html
18181
0644
edit
dl
rm
test.html
78555
0644
edit
dl
rm
text.html
13786
0644
edit
dl
rm
textwrap.html
37998
0644
edit
dl
rm
threading.html
103464
0644
edit
dl
rm
time.html
79629
0644
edit
dl
rm
timeit.html
45249
0644
edit
dl
rm
tk.html
23299
0644
edit
dl
rm
tkinter.html
82932
0644
edit
dl
rm
tkinter.scrolledtext.html
9957
0644
edit
dl
rm
tkinter.tix.html
51858
0644
edit
dl
rm
tkinter.ttk.html
110673
0644
edit
dl
rm
token.html
22660
0644
edit
dl
rm
tokenize.html
32149
0644
edit
dl
rm
trace.html
29145
0644
edit
dl
rm
traceback.html
57588
0644
edit
dl
rm
tracemalloc.html
101144
0644
edit
dl
rm
tty.html
10540
0644
edit
dl
rm
turtle.html
250367
0644
edit
dl
rm
types.html
37060
0644
edit
dl
rm
typing.html
139175
0644
edit
dl
rm
undoc.html
9181
0644
edit
dl
rm
unicodedata.html
21108
0644
edit
dl
rm
unittest.html
250689
0644
edit
dl
rm
unittest.mock-examples.html
168144
0644
edit
dl
rm
unittest.mock.html
300089
0644
edit
dl
rm
unix.html
11780
0644
edit
dl
rm
urllib.error.html
14474
0644
edit
dl
rm
urllib.html
9566
0644
edit
dl
rm
urllib.parse.html
76334
0644
edit
dl
rm
urllib.request.html
177199
0644
edit
dl
rm
urllib.robotparser.html
17156
0644
edit
dl
rm
uu.html
12209
0644
edit
dl
rm
uuid.html
31957
0644
edit
dl
rm
venv.html
73909
0644
edit
dl
rm
warnings.html
50320
0644
edit
dl
rm
wave.html
29868
0644
edit
dl
rm
weakref.html
65292
0644
edit
dl
rm
webbrowser.html
26901
0644
edit
dl
rm
windows.html
10626
0644
edit
dl
rm
winreg.html
66730
0644
edit
dl
rm
winsound.html
21268
0644
edit
dl
rm
wsgiref.html
94492
0644
edit
dl
rm
xdrlib.html
33751
0644
edit
dl
rm
xml.dom.html
97570
0644
edit
dl
rm
xml.dom.minidom.html
41481
0644
edit
dl
rm
xml.dom.pulldom.html
24214
0644
edit
dl
rm
xml.etree.elementtree.html
135491
0644
edit
dl
rm
xml.html
19261
0644
edit
dl
rm
xml.sax.handler.html
42659
0644
edit
dl
rm
xml.sax.html
25515
0644
edit
dl
rm
xml.sax.reader.html
45869
0644
edit
dl
rm
xml.sax.utils.html
16928
0644
edit
dl
rm
xmlrpc.client.html
71947
0644
edit
dl
rm
xmlrpc.html
8535
0644
edit
dl
rm
xmlrpc.server.html
49195
0644
edit
dl
rm
zipapp.html
45105
0644
edit
dl
rm
zipfile.html
80039
0644
edit
dl
rm
zipimport.html
23052
0644
edit
dl
rm
zlib.html
34557
0644
edit
dl
rm
_dummy_thread.html
9193
0644
edit
dl
rm
_thread.html
22588
0644
edit
dl
rm
__future__.html
15792
0644
edit
dl
rm
__main__.html
9019
0644
edit
dl
rm
Edit:
/usr/share/doc/python3-docs/html/library/dis.html
(106191B)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="X-UA-Compatible" content="IE=Edge" /> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>32.12. dis — Disassembler for Python bytecode — Python 3.6.7 documentation</title> <link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" /> <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> <script type="text/javascript" id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script> <script type="text/javascript" src="../_static/jquery.js"></script> <script type="text/javascript" src="../_static/underscore.js"></script> <script type="text/javascript" src="../_static/doctools.js"></script> <script type="text/javascript" src="../_static/sidebar.js"></script> <link rel="search" type="application/opensearchdescription+xml" title="Search within Python 3.6.7 documentation" href="../_static/opensearch.xml"/> <link rel="author" title="About these documents" href="../about.html" /> <link rel="index" title="Index" href="../genindex.html" /> <link rel="search" title="Search" href="../search.html" /> <link rel="copyright" title="Copyright" href="../copyright.html" /> <link rel="next" title="32.13. pickletools — Tools for pickle developers" href="pickletools.html" /> <link rel="prev" title="32.11. compileall — Byte-compile Python libraries" href="compileall.html" /> <link rel="shortcut icon" type="image/png" href="../_static/py.png" /> <link rel="canonical" href="https://docs.python.org/3/library/dis.html" /> <script type="text/javascript" src="../_static/copybutton.js"></script> </head><body> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="pickletools.html" title="32.13. pickletools — Tools for pickle developers" accesskey="N">next</a> |</li> <li class="right" > <a href="compileall.html" title="32.11. compileall — Byte-compile Python libraries" accesskey="P">previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 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">32. Python Language Services</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body" role="main"> <div class="section" id="module-dis"> <span id="dis-disassembler-for-python-bytecode"></span><h1>32.12. <a class="reference internal" href="#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> — Disassembler for Python bytecode<a class="headerlink" href="#module-dis" title="Permalink to this headline">¶</a></h1> <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.6/Lib/dis.py">Lib/dis.py</a></p> <hr class="docutils" /> <p>The <a class="reference internal" href="#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> 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 class="compound-first"><strong>CPython implementation detail:</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="compound-last versionchanged"> <p><span class="versionmodified">Changed in version 3.6: </span>Use 2 bytes for each instruction. Previously the number of bytes varied by instruction.</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="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-python3 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 0 LOAD_GLOBAL 0 (len)</span> <span class="go"> 2 LOAD_FAST 0 (alist)</span> <span class="go"> 4 CALL_FUNCTION 1</span> <span class="go"> 6 RETURN_VALUE</span> </pre></div> </div> <p>(The “2” is a line number).</p> <div class="section" id="bytecode-analysis"> <h2>32.12.1. Bytecode analysis<a class="headerlink" href="#bytecode-analysis" title="Permalink to this headline">¶</a></h2> <div class="versionadded"> <p><span class="versionmodified">New 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="class"> <dt id="dis.Bytecode"> <em class="property">class </em><code class="descclassname">dis.</code><code class="descname">Bytecode</code><span class="sig-paren">(</span><em>x</em>, <em>*</em>, <em>first_line=None</em>, <em>current_offset=None</em><span class="sig-paren">)</span><a class="headerlink" href="#dis.Bytecode" title="Permalink to this definition">¶</a></dt> <dd><p>Analyse the bytecode corresponding to a function, generator, 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 <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> 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> <dl class="classmethod"> <dt id="dis.Bytecode.from_traceback"> <em class="property">classmethod </em><code class="descname">from_traceback</code><span class="sig-paren">(</span><em>tb</em><span class="sig-paren">)</span><a class="headerlink" href="#dis.Bytecode.from_traceback" title="Permalink to this definition">¶</a></dt> <dd><p>Construct 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> instance from the given traceback, setting <em>current_offset</em> to the instruction responsible for the exception.</p> </dd></dl> <dl class="data"> <dt id="dis.Bytecode.codeobj"> <code class="descname">codeobj</code><a class="headerlink" href="#dis.Bytecode.codeobj" title="Permalink to this definition">¶</a></dt> <dd><p>The compiled code object.</p> </dd></dl> <dl class="data"> <dt id="dis.Bytecode.first_line"> <code class="descname">first_line</code><a class="headerlink" href="#dis.Bytecode.first_line" title="Permalink to this definition">¶</a></dt> <dd><p>The first source line of the code object (if available)</p> </dd></dl> <dl class="method"> <dt id="dis.Bytecode.dis"> <code class="descname">dis</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#dis.Bytecode.dis" title="Permalink 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="method"> <dt id="dis.Bytecode.info"> <code class="descname">info</code><span class="sig-paren">(</span><span class="sig-paren">)</span><a class="headerlink" href="#dis.Bytecode.info" title="Permalink 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> </dd></dl> <p>Example:</p> <div class="highlight-python3 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">LOAD_GLOBAL</span> <span class="go">LOAD_FAST</span> <span class="go">CALL_FUNCTION</span> <span class="go">RETURN_VALUE</span> </pre></div> </div> </div> <div class="section" id="analysis-functions"> <h2>32.12.2. Analysis functions<a class="headerlink" href="#analysis-functions" title="Permalink to this headline">¶</a></h2> <p>The <a class="reference internal" href="#module-dis" title="dis: Disassembler for Python bytecode."><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code></a> 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="function"> <dt id="dis.code_info"> <code class="descclassname">dis.</code><code class="descname">code_info</code><span class="sig-paren">(</span><em>x</em><span class="sig-paren">)</span><a class="headerlink" href="#dis.code_info" title="Permalink to this definition">¶</a></dt> <dd><p>Return a formatted multi-line string with detailed code object information for the supplied function, generator, 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">New in version 3.2.</span></p> </div> </dd></dl> <dl class="function"> <dt id="dis.show_code"> <code class="descclassname">dis.</code><code class="descname">show_code</code><span class="sig-paren">(</span><em>x</em>, <em>*</em>, <em>file=None</em><span class="sig-paren">)</span><a class="headerlink" href="#dis.show_code" title="Permalink 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">New in version 3.2.</span></p> </div> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 3.4: </span>Added <em>file</em> parameter.</p> </div> </dd></dl> <dl class="function"> <dt id="dis.dis"> <code class="descclassname">dis.</code><code class="descname">dis</code><span class="sig-paren">(</span><em>x=None</em>, <em>*</em>, <em>file=None</em><span class="sig-paren">)</span><a class="headerlink" href="#dis.dis" title="Permalink 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, 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. 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> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 3.4: </span>Added <em>file</em> parameter.</p> </div> </dd></dl> <dl class="function"> <dt id="dis.distb"> <code class="descclassname">dis.</code><code class="descname">distb</code><span class="sig-paren">(</span><em>tb=None</em>, <em>*</em>, <em>file=None</em><span class="sig-paren">)</span><a class="headerlink" href="#dis.distb" title="Permalink 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 in version 3.4: </span>Added <em>file</em> parameter.</p> </div> </dd></dl> <dl class="function"> <dt id="dis.disassemble"> <code class="descclassname">dis.</code><code class="descname">disassemble</code><span class="sig-paren">(</span><em>code</em>, <em>lasti=-1</em>, <em>*</em>, <em>file=None</em><span class="sig-paren">)</span><a class="headerlink" href="#dis.disassemble" title="Permalink to this definition">¶</a></dt> <dt id="dis.disco"> <code class="descclassname">dis.</code><code class="descname">disco</code><span class="sig-paren">(</span><em>code</em>, <em>lasti=-1</em>, <em>*</em>, <em>file=None</em><span class="sig-paren">)</span><a class="headerlink" href="#dis.disco" title="Permalink 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>the line number, for the first instruction of each line</li> <li>the current instruction, indicated as <code class="docutils literal notranslate"><span class="pre">--></span></code>,</li> <li>a labelled instruction, indicated with <code class="docutils literal notranslate"><span class="pre">>></span></code>,</li> <li>the address of the instruction,</li> <li>the operation code name,</li> <li>operation parameters, and</li> <li>interpretation of the parameters in parentheses.</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 in version 3.4: </span>Added <em>file</em> parameter.</p> </div> </dd></dl> <dl class="function"> <dt id="dis.get_instructions"> <code class="descclassname">dis.</code><code class="descname">get_instructions</code><span class="sig-paren">(</span><em>x</em>, <em>*</em>, <em>first_line=None</em><span class="sig-paren">)</span><a class="headerlink" href="#dis.get_instructions" title="Permalink 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> <div class="versionadded"> <p><span class="versionmodified">New in version 3.4.</span></p> </div> </dd></dl> <dl class="function"> <dt id="dis.findlinestarts"> <code class="descclassname">dis.</code><code class="descname">findlinestarts</code><span class="sig-paren">(</span><em>code</em><span class="sig-paren">)</span><a class="headerlink" href="#dis.findlinestarts" title="Permalink to this definition">¶</a></dt> <dd><p>This generator function uses the <code class="docutils literal notranslate"><span class="pre">co_firstlineno</span></code> and <code class="docutils literal notranslate"><span class="pre">co_lnotab</span></code> attributes of the code object <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. See <a class="reference external" href="https://github.com/python/cpython/tree/3.6/Objects/lnotab_notes.txt">Objects/lnotab_notes.txt</a> for the <code class="docutils literal notranslate"><span class="pre">co_lnotab</span></code> format and how to decode it.</p> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 3.6: </span>Line numbers can be decreasing. Before, they were always increasing.</p> </div> </dd></dl> <dl class="function"> <dt id="dis.findlabels"> <code class="descclassname">dis.</code><code class="descname">findlabels</code><span class="sig-paren">(</span><em>code</em><span class="sig-paren">)</span><a class="headerlink" href="#dis.findlabels" title="Permalink to this definition">¶</a></dt> <dd><p>Detect all offsets in the code object <em>code</em> which are jump targets, and return a list of these offsets.</p> </dd></dl> <dl class="function"> <dt id="dis.stack_effect"> <code class="descclassname">dis.</code><code class="descname">stack_effect</code><span class="sig-paren">(</span><em>opcode</em><span class="optional">[</span>, <em>oparg</em><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#dis.stack_effect" title="Permalink to this definition">¶</a></dt> <dd><p>Compute the stack effect of <em>opcode</em> with argument <em>oparg</em>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.4.</span></p> </div> </dd></dl> </div> <div class="section" id="python-bytecode-instructions"> <span id="bytecodes"></span><h2>32.12.3. Python Bytecode Instructions<a class="headerlink" href="#python-bytecode-instructions" title="Permalink to this headline">¶</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="class"> <dt id="dis.Instruction"> <em class="property">class </em><code class="descclassname">dis.</code><code class="descname">Instruction</code><a class="headerlink" href="#dis.Instruction" title="Permalink to this definition">¶</a></dt> <dd><p>Details for a bytecode operation</p> <dl class="data"> <dt id="dis.Instruction.opcode"> <code class="descname">opcode</code><a class="headerlink" href="#dis.Instruction.opcode" title="Permalink 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="data"> <dt id="dis.Instruction.opname"> <code class="descname">opname</code><a class="headerlink" href="#dis.Instruction.opname" title="Permalink to this definition">¶</a></dt> <dd><p>human readable name for operation</p> </dd></dl> <dl class="data"> <dt id="dis.Instruction.arg"> <code class="descname">arg</code><a class="headerlink" href="#dis.Instruction.arg" title="Permalink 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="data"> <dt id="dis.Instruction.argval"> <code class="descname">argval</code><a class="headerlink" href="#dis.Instruction.argval" title="Permalink to this definition">¶</a></dt> <dd><p>resolved arg value (if known), otherwise same as arg</p> </dd></dl> <dl class="data"> <dt id="dis.Instruction.argrepr"> <code class="descname">argrepr</code><a class="headerlink" href="#dis.Instruction.argrepr" title="Permalink to this definition">¶</a></dt> <dd><p>human readable description of operation argument</p> </dd></dl> <dl class="data"> <dt id="dis.Instruction.offset"> <code class="descname">offset</code><a class="headerlink" href="#dis.Instruction.offset" title="Permalink to this definition">¶</a></dt> <dd><p>start index of operation within bytecode sequence</p> </dd></dl> <dl class="data"> <dt id="dis.Instruction.starts_line"> <code class="descname">starts_line</code><a class="headerlink" href="#dis.Instruction.starts_line" title="Permalink to this definition">¶</a></dt> <dd><p>line started by this opcode (if any), otherwise <code class="docutils literal notranslate"><span class="pre">None</span></code></p> </dd></dl> <dl class="data"> <dt id="dis.Instruction.is_jump_target"> <code class="descname">is_jump_target</code><a class="headerlink" href="#dis.Instruction.is_jump_target" title="Permalink 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> <div class="versionadded"> <p><span class="versionmodified">New in version 3.4.</span></p> </div> </dd></dl> <p>The Python compiler currently generates the following bytecode instructions.</p> <p><strong>General instructions</strong></p> <dl class="opcode"> <dt id="opcode-NOP"> <code class="descname">NOP</code><a class="headerlink" href="#opcode-NOP" title="Permalink to this definition">¶</a></dt> <dd><p>Do nothing code. Used as a placeholder by the bytecode optimizer.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-POP_TOP"> <code class="descname">POP_TOP</code><a class="headerlink" href="#opcode-POP_TOP" title="Permalink to this definition">¶</a></dt> <dd><p>Removes the top-of-stack (TOS) item.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-ROT_TWO"> <code class="descname">ROT_TWO</code><a class="headerlink" href="#opcode-ROT_TWO" title="Permalink to this definition">¶</a></dt> <dd><p>Swaps the two top-most stack items.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-ROT_THREE"> <code class="descname">ROT_THREE</code><a class="headerlink" href="#opcode-ROT_THREE" title="Permalink to this definition">¶</a></dt> <dd><p>Lifts second and third stack item one position up, moves top down to position three.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-DUP_TOP"> <code class="descname">DUP_TOP</code><a class="headerlink" href="#opcode-DUP_TOP" title="Permalink to this definition">¶</a></dt> <dd><p>Duplicates the reference on top of the stack.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.2.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-DUP_TOP_TWO"> <code class="descname">DUP_TOP_TWO</code><a class="headerlink" href="#opcode-DUP_TOP_TWO" title="Permalink to this definition">¶</a></dt> <dd><p>Duplicates the two references on top of the stack, leaving them in the same order.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.2.</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="opcode"> <dt id="opcode-UNARY_POSITIVE"> <code class="descname">UNARY_POSITIVE</code><a class="headerlink" href="#opcode-UNARY_POSITIVE" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">+TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-UNARY_NEGATIVE"> <code class="descname">UNARY_NEGATIVE</code><a class="headerlink" href="#opcode-UNARY_NEGATIVE" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">-TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-UNARY_NOT"> <code class="descname">UNARY_NOT</code><a class="headerlink" href="#opcode-UNARY_NOT" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">not</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-UNARY_INVERT"> <code class="descname">UNARY_INVERT</code><a class="headerlink" href="#opcode-UNARY_INVERT" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">~TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-GET_ITER"> <code class="descname">GET_ITER</code><a class="headerlink" href="#opcode-GET_ITER" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">iter(TOS)</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-GET_YIELD_FROM_ITER"> <code class="descname">GET_YIELD_FROM_ITER</code><a class="headerlink" href="#opcode-GET_YIELD_FROM_ITER" title="Permalink to this definition">¶</a></dt> <dd><p>If <code class="docutils literal notranslate"><span class="pre">TOS</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">TOS</span> <span class="pre">=</span> <span class="pre">iter(TOS)</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <p><strong>Binary operations</strong></p> <p>Binary operations remove the top of the stack (TOS) and the second top-most stack item (TOS1) from the stack. They perform the operation, and put the result back on the stack.</p> <dl class="opcode"> <dt id="opcode-BINARY_POWER"> <code class="descname">BINARY_POWER</code><a class="headerlink" href="#opcode-BINARY_POWER" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">**</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_MULTIPLY"> <code class="descname">BINARY_MULTIPLY</code><a class="headerlink" href="#opcode-BINARY_MULTIPLY" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">*</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_MATRIX_MULTIPLY"> <code class="descname">BINARY_MATRIX_MULTIPLY</code><a class="headerlink" href="#opcode-BINARY_MATRIX_MULTIPLY" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">@</span> <span class="pre">TOS</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_FLOOR_DIVIDE"> <code class="descname">BINARY_FLOOR_DIVIDE</code><a class="headerlink" href="#opcode-BINARY_FLOOR_DIVIDE" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">//</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_TRUE_DIVIDE"> <code class="descname">BINARY_TRUE_DIVIDE</code><a class="headerlink" href="#opcode-BINARY_TRUE_DIVIDE" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">/</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_MODULO"> <code class="descname">BINARY_MODULO</code><a class="headerlink" href="#opcode-BINARY_MODULO" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">%</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_ADD"> <code class="descname">BINARY_ADD</code><a class="headerlink" href="#opcode-BINARY_ADD" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">+</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_SUBTRACT"> <code class="descname">BINARY_SUBTRACT</code><a class="headerlink" href="#opcode-BINARY_SUBTRACT" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">-</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_SUBSCR"> <code class="descname">BINARY_SUBSCR</code><a class="headerlink" href="#opcode-BINARY_SUBSCR" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1[TOS]</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_LSHIFT"> <code class="descname">BINARY_LSHIFT</code><a class="headerlink" href="#opcode-BINARY_LSHIFT" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre"><<</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_RSHIFT"> <code class="descname">BINARY_RSHIFT</code><a class="headerlink" href="#opcode-BINARY_RSHIFT" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">>></span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_AND"> <code class="descname">BINARY_AND</code><a class="headerlink" href="#opcode-BINARY_AND" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">&</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_XOR"> <code class="descname">BINARY_XOR</code><a class="headerlink" href="#opcode-BINARY_XOR" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">^</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BINARY_OR"> <code class="descname">BINARY_OR</code><a class="headerlink" href="#opcode-BINARY_OR" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">|</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <p><strong>In-place operations</strong></p> <p>In-place operations are like binary operations, in that they remove TOS and TOS1, and push the result back on the stack, but the operation is done in-place when TOS1 supports it, and the resulting TOS may be (but does not have to be) the original TOS1.</p> <dl class="opcode"> <dt id="opcode-INPLACE_POWER"> <code class="descname">INPLACE_POWER</code><a class="headerlink" href="#opcode-INPLACE_POWER" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">**</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_MULTIPLY"> <code class="descname">INPLACE_MULTIPLY</code><a class="headerlink" href="#opcode-INPLACE_MULTIPLY" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">*</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_MATRIX_MULTIPLY"> <code class="descname">INPLACE_MATRIX_MULTIPLY</code><a class="headerlink" href="#opcode-INPLACE_MATRIX_MULTIPLY" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">@</span> <span class="pre">TOS</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_FLOOR_DIVIDE"> <code class="descname">INPLACE_FLOOR_DIVIDE</code><a class="headerlink" href="#opcode-INPLACE_FLOOR_DIVIDE" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">//</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_TRUE_DIVIDE"> <code class="descname">INPLACE_TRUE_DIVIDE</code><a class="headerlink" href="#opcode-INPLACE_TRUE_DIVIDE" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">/</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_MODULO"> <code class="descname">INPLACE_MODULO</code><a class="headerlink" href="#opcode-INPLACE_MODULO" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">%</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_ADD"> <code class="descname">INPLACE_ADD</code><a class="headerlink" href="#opcode-INPLACE_ADD" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">+</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_SUBTRACT"> <code class="descname">INPLACE_SUBTRACT</code><a class="headerlink" href="#opcode-INPLACE_SUBTRACT" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">-</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_LSHIFT"> <code class="descname">INPLACE_LSHIFT</code><a class="headerlink" href="#opcode-INPLACE_LSHIFT" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre"><<</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_RSHIFT"> <code class="descname">INPLACE_RSHIFT</code><a class="headerlink" href="#opcode-INPLACE_RSHIFT" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">>></span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_AND"> <code class="descname">INPLACE_AND</code><a class="headerlink" href="#opcode-INPLACE_AND" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">&</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_XOR"> <code class="descname">INPLACE_XOR</code><a class="headerlink" href="#opcode-INPLACE_XOR" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">^</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-INPLACE_OR"> <code class="descname">INPLACE_OR</code><a class="headerlink" href="#opcode-INPLACE_OR" title="Permalink to this definition">¶</a></dt> <dd><p>Implements in-place <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">TOS1</span> <span class="pre">|</span> <span class="pre">TOS</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-STORE_SUBSCR"> <code class="descname">STORE_SUBSCR</code><a class="headerlink" href="#opcode-STORE_SUBSCR" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS1[TOS]</span> <span class="pre">=</span> <span class="pre">TOS2</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-DELETE_SUBSCR"> <code class="descname">DELETE_SUBSCR</code><a class="headerlink" href="#opcode-DELETE_SUBSCR" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">del</span> <span class="pre">TOS1[TOS]</span></code>.</p> </dd></dl> <p><strong>Coroutine opcodes</strong></p> <dl class="opcode"> <dt id="opcode-GET_AWAITABLE"> <code class="descname">GET_AWAITABLE</code><a class="headerlink" href="#opcode-GET_AWAITABLE" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">get_awaitable(TOS)</span></code>, where <code class="docutils literal notranslate"><span class="pre">get_awaitable(o)</span></code> returns <code class="docutils literal notranslate"><span class="pre">o</span></code> if <code class="docutils literal notranslate"><span class="pre">o</span></code> is a coroutine object or a generator object with the CO_ITERABLE_COROUTINE flag, or resolves <code class="docutils literal notranslate"><span class="pre">o.__await__</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-GET_AITER"> <code class="descname">GET_AITER</code><a class="headerlink" href="#opcode-GET_AITER" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS</span> <span class="pre">=</span> <span class="pre">get_awaitable(TOS.__aiter__())</span></code>. See <code class="docutils literal notranslate"><span class="pre">GET_AWAITABLE</span></code> for details about <code class="docutils literal notranslate"><span class="pre">get_awaitable</span></code></p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-GET_ANEXT"> <code class="descname">GET_ANEXT</code><a class="headerlink" href="#opcode-GET_ANEXT" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">PUSH(get_awaitable(TOS.__anext__()))</span></code>. See <code class="docutils literal notranslate"><span class="pre">GET_AWAITABLE</span></code> for details about <code class="docutils literal notranslate"><span class="pre">get_awaitable</span></code></p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-BEFORE_ASYNC_WITH"> <code class="descname">BEFORE_ASYNC_WITH</code><a class="headerlink" href="#opcode-BEFORE_ASYNC_WITH" title="Permalink to this definition">¶</a></dt> <dd><p>Resolves <code class="docutils literal notranslate"><span class="pre">__aenter__</span></code> and <code class="docutils literal notranslate"><span class="pre">__aexit__</span></code> from the object on top of the stack. Pushes <code class="docutils literal notranslate"><span class="pre">__aexit__</span></code> and result of <code class="docutils literal notranslate"><span class="pre">__aenter__()</span></code> to the stack.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-SETUP_ASYNC_WITH"> <code class="descname">SETUP_ASYNC_WITH</code><a class="headerlink" href="#opcode-SETUP_ASYNC_WITH" title="Permalink to this definition">¶</a></dt> <dd><p>Creates a new frame object.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <p><strong>Miscellaneous opcodes</strong></p> <dl class="opcode"> <dt id="opcode-PRINT_EXPR"> <code class="descname">PRINT_EXPR</code><a class="headerlink" href="#opcode-PRINT_EXPR" title="Permalink to this definition">¶</a></dt> <dd><p>Implements the expression statement for the interactive mode. TOS is removed from the stack and printed. In non-interactive mode, an expression statement is terminated with <a class="reference internal" href="#opcode-POP_TOP"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_TOP</span></code></a>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BREAK_LOOP"> <code class="descname">BREAK_LOOP</code><a class="headerlink" href="#opcode-BREAK_LOOP" title="Permalink to this definition">¶</a></dt> <dd><p>Terminates a loop due to a <a class="reference internal" href="../reference/simple_stmts.html#break"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">break</span></code></a> statement.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-CONTINUE_LOOP"> <code class="descname">CONTINUE_LOOP</code><span class="sig-paren">(</span><em>target</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-CONTINUE_LOOP" title="Permalink to this definition">¶</a></dt> <dd><p>Continues a loop due to a <a class="reference internal" href="../reference/simple_stmts.html#continue"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">continue</span></code></a> statement. <em>target</em> is the address to jump to (which should be a <a class="reference internal" href="#opcode-FOR_ITER"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">FOR_ITER</span></code></a> instruction).</p> </dd></dl> <dl class="opcode"> <dt id="opcode-SET_ADD"> <code class="descname">SET_ADD</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-SET_ADD" title="Permalink to this definition">¶</a></dt> <dd><p>Calls <code class="docutils literal notranslate"><span class="pre">set.add(TOS1[-i],</span> <span class="pre">TOS)</span></code>. Used to implement set comprehensions.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-LIST_APPEND"> <code class="descname">LIST_APPEND</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-LIST_APPEND" title="Permalink to this definition">¶</a></dt> <dd><p>Calls <code class="docutils literal notranslate"><span class="pre">list.append(TOS[-i],</span> <span class="pre">TOS)</span></code>. Used to implement list comprehensions.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-MAP_ADD"> <code class="descname">MAP_ADD</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-MAP_ADD" title="Permalink to this definition">¶</a></dt> <dd><p>Calls <code class="docutils literal notranslate"><span class="pre">dict.setitem(TOS1[-i],</span> <span class="pre">TOS,</span> <span class="pre">TOS1)</span></code>. Used to implement dict comprehensions.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.1.</span></p> </div> </dd></dl> <p>For all of the <a class="reference internal" href="#opcode-SET_ADD"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">SET_ADD</span></code></a>, <a class="reference internal" href="#opcode-LIST_APPEND"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LIST_APPEND</span></code></a> and <a class="reference internal" href="#opcode-MAP_ADD"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">MAP_ADD</span></code></a> instructions, while the added value or key/value pair is popped off, the container object remains on the stack so that it is available for further iterations of the loop.</p> <dl class="opcode"> <dt id="opcode-RETURN_VALUE"> <code class="descname">RETURN_VALUE</code><a class="headerlink" href="#opcode-RETURN_VALUE" title="Permalink to this definition">¶</a></dt> <dd><p>Returns with TOS to the caller of the function.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-YIELD_VALUE"> <code class="descname">YIELD_VALUE</code><a class="headerlink" href="#opcode-YIELD_VALUE" title="Permalink to this definition">¶</a></dt> <dd><p>Pops TOS and yields it from a <a class="reference internal" href="../glossary.html#term-generator"><span class="xref std std-term">generator</span></a>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-YIELD_FROM"> <code class="descname">YIELD_FROM</code><a class="headerlink" href="#opcode-YIELD_FROM" title="Permalink to this definition">¶</a></dt> <dd><p>Pops TOS and delegates to it as a subiterator from a <a class="reference internal" href="../glossary.html#term-generator"><span class="xref std std-term">generator</span></a>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.3.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-SETUP_ANNOTATIONS"> <code class="descname">SETUP_ANNOTATIONS</code><a class="headerlink" href="#opcode-SETUP_ANNOTATIONS" title="Permalink to this definition">¶</a></dt> <dd><p>Checks whether <code class="docutils literal notranslate"><span class="pre">__annotations__</span></code> is defined in <code class="docutils literal notranslate"><span class="pre">locals()</span></code>, if not it is set up to an empty <code class="docutils literal notranslate"><span class="pre">dict</span></code>. This opcode is only emitted if a class or module body contains <a class="reference internal" href="../glossary.html#term-variable-annotation"><span class="xref std std-term">variable annotations</span></a> statically.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.6.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-IMPORT_STAR"> <code class="descname">IMPORT_STAR</code><a class="headerlink" href="#opcode-IMPORT_STAR" title="Permalink to this definition">¶</a></dt> <dd><p>Loads all symbols not starting with <code class="docutils literal notranslate"><span class="pre">'_'</span></code> directly from the module TOS to the local namespace. The module is popped after loading all names. This opcode implements <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">module</span> <span class="pre">import</span> <span class="pre">*</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-POP_BLOCK"> <code class="descname">POP_BLOCK</code><a class="headerlink" href="#opcode-POP_BLOCK" title="Permalink to this definition">¶</a></dt> <dd><p>Removes one block from the block stack. Per frame, there is a stack of blocks, denoting nested loops, try statements, and such.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-POP_EXCEPT"> <code class="descname">POP_EXCEPT</code><a class="headerlink" href="#opcode-POP_EXCEPT" title="Permalink to this definition">¶</a></dt> <dd><p>Removes one block from the block stack. The popped block must be an exception handler block, as implicitly created when entering an except handler. In addition to popping extraneous values from the frame stack, the last three popped values are used to restore the exception state.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-END_FINALLY"> <code class="descname">END_FINALLY</code><a class="headerlink" href="#opcode-END_FINALLY" title="Permalink to this definition">¶</a></dt> <dd><p>Terminates a <a class="reference internal" href="../reference/compound_stmts.html#finally"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">finally</span></code></a> clause. The interpreter recalls whether the exception has to be re-raised, or whether the function returns, and continues with the outer-next block.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-LOAD_BUILD_CLASS"> <code class="descname">LOAD_BUILD_CLASS</code><a class="headerlink" href="#opcode-LOAD_BUILD_CLASS" title="Permalink to this definition">¶</a></dt> <dd><p>Pushes <code class="xref py py-func docutils literal notranslate"><span class="pre">builtins.__build_class__()</span></code> onto the stack. It is later called by <a class="reference internal" href="#opcode-CALL_FUNCTION"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">CALL_FUNCTION</span></code></a> to construct a class.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-SETUP_WITH"> <code class="descname">SETUP_WITH</code><span class="sig-paren">(</span><em>delta</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-SETUP_WITH" title="Permalink to this definition">¶</a></dt> <dd><p>This opcode performs several operations before a with block starts. First, it loads <a class="reference internal" href="../reference/datamodel.html#object.__exit__" title="object.__exit__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__exit__()</span></code></a> from the context manager and pushes it onto the stack for later use by <code class="xref std std-opcode docutils literal notranslate"><span class="pre">WITH_CLEANUP</span></code>. Then, <a class="reference internal" href="../reference/datamodel.html#object.__enter__" title="object.__enter__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__enter__()</span></code></a> is called, and a finally block pointing to <em>delta</em> is pushed. Finally, the result of calling the enter method is pushed onto the stack. The next opcode will either ignore it (<a class="reference internal" href="#opcode-POP_TOP"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">POP_TOP</span></code></a>), or store it in (a) variable(s) (<a class="reference internal" href="#opcode-STORE_FAST"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_FAST</span></code></a>, <a class="reference internal" href="#opcode-STORE_NAME"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_NAME</span></code></a>, or <a class="reference internal" href="#opcode-UNPACK_SEQUENCE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">UNPACK_SEQUENCE</span></code></a>).</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.2.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-WITH_CLEANUP_START"> <code class="descname">WITH_CLEANUP_START</code><a class="headerlink" href="#opcode-WITH_CLEANUP_START" title="Permalink to this definition">¶</a></dt> <dd><p>Cleans up the stack when a <a class="reference internal" href="../reference/compound_stmts.html#with"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">with</span></code></a> statement block exits. TOS is the context manager’s <a class="reference internal" href="../reference/datamodel.html#object.__exit__" title="object.__exit__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__exit__()</span></code></a> bound method. Below TOS are 1–3 values indicating how/why the finally clause was entered:</p> <ul class="simple"> <li>SECOND = <code class="docutils literal notranslate"><span class="pre">None</span></code></li> <li>(SECOND, THIRD) = (<code class="docutils literal notranslate"><span class="pre">WHY_{RETURN,CONTINUE}</span></code>), retval</li> <li>SECOND = <code class="docutils literal notranslate"><span class="pre">WHY_*</span></code>; no retval below it</li> <li>(SECOND, THIRD, FOURTH) = exc_info()</li> </ul> <p>In the last case, <code class="docutils literal notranslate"><span class="pre">TOS(SECOND,</span> <span class="pre">THIRD,</span> <span class="pre">FOURTH)</span></code> is called, otherwise <code class="docutils literal notranslate"><span class="pre">TOS(None,</span> <span class="pre">None,</span> <span class="pre">None)</span></code>. Pushes SECOND and result of the call to the stack.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-WITH_CLEANUP_FINISH"> <code class="descname">WITH_CLEANUP_FINISH</code><a class="headerlink" href="#opcode-WITH_CLEANUP_FINISH" title="Permalink to this definition">¶</a></dt> <dd><p>Pops exception type and result of ‘exit’ function call from the stack.</p> <p>If the stack represents an exception, <em>and</em> the function call returns a ‘true’ value, this information is “zapped” and replaced with a single <code class="docutils literal notranslate"><span class="pre">WHY_SILENCED</span></code> to prevent <a class="reference internal" href="#opcode-END_FINALLY"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">END_FINALLY</span></code></a> from re-raising the exception. (But non-local gotos will still be resumed.)</p> </dd></dl> <p>All of the following opcodes use their arguments.</p> <dl class="opcode"> <dt id="opcode-STORE_NAME"> <code class="descname">STORE_NAME</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-STORE_NAME" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">name</span> <span class="pre">=</span> <span class="pre">TOS</span></code>. <em>namei</em> is the index of <em>name</em> in the attribute <code class="xref py py-attr docutils literal notranslate"><span class="pre">co_names</span></code> of the code object. The compiler tries to use <a class="reference internal" href="#opcode-STORE_FAST"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_FAST</span></code></a> or <a class="reference internal" href="#opcode-STORE_GLOBAL"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_GLOBAL</span></code></a> if possible.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-DELETE_NAME"> <code class="descname">DELETE_NAME</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-DELETE_NAME" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">del</span> <span class="pre">name</span></code>, where <em>namei</em> is the index into <code class="xref py py-attr docutils literal notranslate"><span class="pre">co_names</span></code> attribute of the code object.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-UNPACK_SEQUENCE"> <code class="descname">UNPACK_SEQUENCE</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-UNPACK_SEQUENCE" title="Permalink to this definition">¶</a></dt> <dd><p>Unpacks TOS into <em>count</em> individual values, which are put onto the stack right-to-left.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-UNPACK_EX"> <code class="descname">UNPACK_EX</code><span class="sig-paren">(</span><em>counts</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-UNPACK_EX" title="Permalink to this definition">¶</a></dt> <dd><p>Implements assignment with a starred target: Unpacks an iterable in TOS into individual values, where the total number of values can be smaller than the number of items in the iterable: one of the new values will be a list of all leftover items.</p> <p>The low byte of <em>counts</em> is the number of values before the list value, the high byte of <em>counts</em> the number of values after it. The resulting values are put onto the stack right-to-left.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-STORE_ATTR"> <code class="descname">STORE_ATTR</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-STORE_ATTR" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">TOS.name</span> <span class="pre">=</span> <span class="pre">TOS1</span></code>, where <em>namei</em> is the index of name in <code class="xref py py-attr docutils literal notranslate"><span class="pre">co_names</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-DELETE_ATTR"> <code class="descname">DELETE_ATTR</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-DELETE_ATTR" title="Permalink to this definition">¶</a></dt> <dd><p>Implements <code class="docutils literal notranslate"><span class="pre">del</span> <span class="pre">TOS.name</span></code>, using <em>namei</em> as index into <code class="xref py py-attr docutils literal notranslate"><span class="pre">co_names</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-STORE_GLOBAL"> <code class="descname">STORE_GLOBAL</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-STORE_GLOBAL" title="Permalink to this definition">¶</a></dt> <dd><p>Works as <a class="reference internal" href="#opcode-STORE_NAME"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_NAME</span></code></a>, but stores the name as a global.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-DELETE_GLOBAL"> <code class="descname">DELETE_GLOBAL</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-DELETE_GLOBAL" title="Permalink to this definition">¶</a></dt> <dd><p>Works as <a class="reference internal" href="#opcode-DELETE_NAME"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">DELETE_NAME</span></code></a>, but deletes a global name.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-LOAD_CONST"> <code class="descname">LOAD_CONST</code><span class="sig-paren">(</span><em>consti</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-LOAD_CONST" title="Permalink to this definition">¶</a></dt> <dd><p>Pushes <code class="docutils literal notranslate"><span class="pre">co_consts[consti]</span></code> onto the stack.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-LOAD_NAME"> <code class="descname">LOAD_NAME</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-LOAD_NAME" title="Permalink to this definition">¶</a></dt> <dd><p>Pushes the value associated with <code class="docutils literal notranslate"><span class="pre">co_names[namei]</span></code> onto the stack.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_TUPLE"> <code class="descname">BUILD_TUPLE</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_TUPLE" title="Permalink to this definition">¶</a></dt> <dd><p>Creates a tuple consuming <em>count</em> items from the stack, and pushes the resulting tuple onto the stack.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_LIST"> <code class="descname">BUILD_LIST</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_LIST" title="Permalink to this definition">¶</a></dt> <dd><p>Works as <a class="reference internal" href="#opcode-BUILD_TUPLE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_TUPLE</span></code></a>, but creates a list.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_SET"> <code class="descname">BUILD_SET</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_SET" title="Permalink to this definition">¶</a></dt> <dd><p>Works as <a class="reference internal" href="#opcode-BUILD_TUPLE"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_TUPLE</span></code></a>, but creates a set.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_MAP"> <code class="descname">BUILD_MAP</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_MAP" title="Permalink to this definition">¶</a></dt> <dd><p>Pushes a new dictionary object onto the stack. Pops <code class="docutils literal notranslate"><span class="pre">2</span> <span class="pre">*</span> <span class="pre">count</span></code> items so that the dictionary holds <em>count</em> entries: <code class="docutils literal notranslate"><span class="pre">{...,</span> <span class="pre">TOS3:</span> <span class="pre">TOS2,</span> <span class="pre">TOS1:</span> <span class="pre">TOS}</span></code>.</p> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 3.5: </span>The dictionary is created from stack items instead of creating an empty dictionary pre-sized to hold <em>count</em> items.</p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_CONST_KEY_MAP"> <code class="descname">BUILD_CONST_KEY_MAP</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_CONST_KEY_MAP" title="Permalink to this definition">¶</a></dt> <dd><p>The version of <a class="reference internal" href="#opcode-BUILD_MAP"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_MAP</span></code></a> specialized for constant keys. <em>count</em> values are consumed from the stack. The top element on the stack contains a tuple of keys.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.6.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_STRING"> <code class="descname">BUILD_STRING</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_STRING" title="Permalink to this definition">¶</a></dt> <dd><p>Concatenates <em>count</em> strings from the stack and pushes the resulting string onto the stack.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.6.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_TUPLE_UNPACK"> <code class="descname">BUILD_TUPLE_UNPACK</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_TUPLE_UNPACK" title="Permalink to this definition">¶</a></dt> <dd><p>Pops <em>count</em> iterables from the stack, joins them in a single tuple, and pushes the result. Implements iterable unpacking in tuple displays <code class="docutils literal notranslate"><span class="pre">(*x,</span> <span class="pre">*y,</span> <span class="pre">*z)</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_TUPLE_UNPACK_WITH_CALL"> <code class="descname">BUILD_TUPLE_UNPACK_WITH_CALL</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_TUPLE_UNPACK_WITH_CALL" title="Permalink to this definition">¶</a></dt> <dd><p>This is similar to <a class="reference internal" href="#opcode-BUILD_TUPLE_UNPACK"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_TUPLE_UNPACK</span></code></a>, but is used for <code class="docutils literal notranslate"><span class="pre">f(*x,</span> <span class="pre">*y,</span> <span class="pre">*z)</span></code> call syntax. The stack item at position <code class="docutils literal notranslate"><span class="pre">count</span> <span class="pre">+</span> <span class="pre">1</span></code> should be the corresponding callable <code class="docutils literal notranslate"><span class="pre">f</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.6.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_LIST_UNPACK"> <code class="descname">BUILD_LIST_UNPACK</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_LIST_UNPACK" title="Permalink to this definition">¶</a></dt> <dd><p>This is similar to <a class="reference internal" href="#opcode-BUILD_TUPLE_UNPACK"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_TUPLE_UNPACK</span></code></a>, but pushes a list instead of tuple. Implements iterable unpacking in list displays <code class="docutils literal notranslate"><span class="pre">[*x,</span> <span class="pre">*y,</span> <span class="pre">*z]</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_SET_UNPACK"> <code class="descname">BUILD_SET_UNPACK</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_SET_UNPACK" title="Permalink to this definition">¶</a></dt> <dd><p>This is similar to <a class="reference internal" href="#opcode-BUILD_TUPLE_UNPACK"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_TUPLE_UNPACK</span></code></a>, but pushes a set instead of tuple. Implements iterable unpacking in set displays <code class="docutils literal notranslate"><span class="pre">{*x,</span> <span class="pre">*y,</span> <span class="pre">*z}</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_MAP_UNPACK"> <code class="descname">BUILD_MAP_UNPACK</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_MAP_UNPACK" title="Permalink to this definition">¶</a></dt> <dd><p>Pops <em>count</em> mappings from the stack, merges them into a single dictionary, and pushes the result. Implements dictionary unpacking in dictionary displays <code class="docutils literal notranslate"><span class="pre">{**x,</span> <span class="pre">**y,</span> <span class="pre">**z}</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_MAP_UNPACK_WITH_CALL"> <code class="descname">BUILD_MAP_UNPACK_WITH_CALL</code><span class="sig-paren">(</span><em>count</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_MAP_UNPACK_WITH_CALL" title="Permalink to this definition">¶</a></dt> <dd><p>This is similar to <a class="reference internal" href="#opcode-BUILD_MAP_UNPACK"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_MAP_UNPACK</span></code></a>, but is used for <code class="docutils literal notranslate"><span class="pre">f(**x,</span> <span class="pre">**y,</span> <span class="pre">**z)</span></code> call syntax. The stack item at position <code class="docutils literal notranslate"><span class="pre">count</span> <span class="pre">+</span> <span class="pre">2</span></code> should be the corresponding callable <code class="docutils literal notranslate"><span class="pre">f</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.5.</span></p> </div> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 3.6: </span>The position of the callable is determined by adding 2 to the opcode argument instead of encoding it in the second byte of the argument.</p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-LOAD_ATTR"> <code class="descname">LOAD_ATTR</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-LOAD_ATTR" title="Permalink to this definition">¶</a></dt> <dd><p>Replaces TOS with <code class="docutils literal notranslate"><span class="pre">getattr(TOS,</span> <span class="pre">co_names[namei])</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-COMPARE_OP"> <code class="descname">COMPARE_OP</code><span class="sig-paren">(</span><em>opname</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-COMPARE_OP" title="Permalink to this definition">¶</a></dt> <dd><p>Performs a Boolean operation. The operation name can be found in <code class="docutils literal notranslate"><span class="pre">cmp_op[opname]</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-IMPORT_NAME"> <code class="descname">IMPORT_NAME</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-IMPORT_NAME" title="Permalink to this definition">¶</a></dt> <dd><p>Imports the module <code class="docutils literal notranslate"><span class="pre">co_names[namei]</span></code>. TOS and TOS1 are popped and provide the <em>fromlist</em> and <em>level</em> arguments of <a class="reference internal" href="functions.html#__import__" title="__import__"><code class="xref py py-func docutils literal notranslate"><span class="pre">__import__()</span></code></a>. The module object is pushed onto the stack. The current namespace is not affected: for a proper import statement, a subsequent <a class="reference internal" href="#opcode-STORE_FAST"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_FAST</span></code></a> instruction modifies the namespace.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-IMPORT_FROM"> <code class="descname">IMPORT_FROM</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-IMPORT_FROM" title="Permalink to this definition">¶</a></dt> <dd><p>Loads the attribute <code class="docutils literal notranslate"><span class="pre">co_names[namei]</span></code> from the module found in TOS. The resulting object is pushed onto the stack, to be subsequently stored by a <a class="reference internal" href="#opcode-STORE_FAST"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">STORE_FAST</span></code></a> instruction.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-JUMP_FORWARD"> <code class="descname">JUMP_FORWARD</code><span class="sig-paren">(</span><em>delta</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-JUMP_FORWARD" title="Permalink to this definition">¶</a></dt> <dd><p>Increments bytecode counter by <em>delta</em>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-POP_JUMP_IF_TRUE"> <code class="descname">POP_JUMP_IF_TRUE</code><span class="sig-paren">(</span><em>target</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-POP_JUMP_IF_TRUE" title="Permalink to this definition">¶</a></dt> <dd><p>If TOS is true, sets the bytecode counter to <em>target</em>. TOS is popped.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.1.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-POP_JUMP_IF_FALSE"> <code class="descname">POP_JUMP_IF_FALSE</code><span class="sig-paren">(</span><em>target</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-POP_JUMP_IF_FALSE" title="Permalink to this definition">¶</a></dt> <dd><p>If TOS is false, sets the bytecode counter to <em>target</em>. TOS is popped.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.1.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-JUMP_IF_TRUE_OR_POP"> <code class="descname">JUMP_IF_TRUE_OR_POP</code><span class="sig-paren">(</span><em>target</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-JUMP_IF_TRUE_OR_POP" title="Permalink to this definition">¶</a></dt> <dd><p>If TOS is true, sets the bytecode counter to <em>target</em> and leaves TOS on the stack. Otherwise (TOS is false), TOS is popped.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.1.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-JUMP_IF_FALSE_OR_POP"> <code class="descname">JUMP_IF_FALSE_OR_POP</code><span class="sig-paren">(</span><em>target</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-JUMP_IF_FALSE_OR_POP" title="Permalink to this definition">¶</a></dt> <dd><p>If TOS is false, sets the bytecode counter to <em>target</em> and leaves TOS on the stack. Otherwise (TOS is true), TOS is popped.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.1.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-JUMP_ABSOLUTE"> <code class="descname">JUMP_ABSOLUTE</code><span class="sig-paren">(</span><em>target</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-JUMP_ABSOLUTE" title="Permalink to this definition">¶</a></dt> <dd><p>Set bytecode counter to <em>target</em>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-FOR_ITER"> <code class="descname">FOR_ITER</code><span class="sig-paren">(</span><em>delta</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-FOR_ITER" title="Permalink to this definition">¶</a></dt> <dd><p>TOS is an <a class="reference internal" href="../glossary.html#term-iterator"><span class="xref std std-term">iterator</span></a>. Call its <a class="reference internal" href="stdtypes.html#iterator.__next__" title="iterator.__next__"><code class="xref py py-meth docutils literal notranslate"><span class="pre">__next__()</span></code></a> method. If this yields a new value, push it on the stack (leaving the iterator below it). If the iterator indicates it is exhausted TOS is popped, and the byte code counter is incremented by <em>delta</em>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-LOAD_GLOBAL"> <code class="descname">LOAD_GLOBAL</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-LOAD_GLOBAL" title="Permalink to this definition">¶</a></dt> <dd><p>Loads the global named <code class="docutils literal notranslate"><span class="pre">co_names[namei]</span></code> onto the stack.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-SETUP_LOOP"> <code class="descname">SETUP_LOOP</code><span class="sig-paren">(</span><em>delta</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-SETUP_LOOP" title="Permalink to this definition">¶</a></dt> <dd><p>Pushes a block for a loop onto the block stack. The block spans from the current instruction with a size of <em>delta</em> bytes.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-SETUP_EXCEPT"> <code class="descname">SETUP_EXCEPT</code><span class="sig-paren">(</span><em>delta</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-SETUP_EXCEPT" title="Permalink to this definition">¶</a></dt> <dd><p>Pushes a try block from a try-except clause onto the block stack. <em>delta</em> points to the first except block.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-SETUP_FINALLY"> <code class="descname">SETUP_FINALLY</code><span class="sig-paren">(</span><em>delta</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-SETUP_FINALLY" title="Permalink to this definition">¶</a></dt> <dd><p>Pushes a try block from a try-except clause onto the block stack. <em>delta</em> points to the finally block.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-LOAD_FAST"> <code class="descname">LOAD_FAST</code><span class="sig-paren">(</span><em>var_num</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-LOAD_FAST" title="Permalink to this definition">¶</a></dt> <dd><p>Pushes a reference to the local <code class="docutils literal notranslate"><span class="pre">co_varnames[var_num]</span></code> onto the stack.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-STORE_FAST"> <code class="descname">STORE_FAST</code><span class="sig-paren">(</span><em>var_num</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-STORE_FAST" title="Permalink to this definition">¶</a></dt> <dd><p>Stores TOS into the local <code class="docutils literal notranslate"><span class="pre">co_varnames[var_num]</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-DELETE_FAST"> <code class="descname">DELETE_FAST</code><span class="sig-paren">(</span><em>var_num</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-DELETE_FAST" title="Permalink to this definition">¶</a></dt> <dd><p>Deletes local <code class="docutils literal notranslate"><span class="pre">co_varnames[var_num]</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-STORE_ANNOTATION"> <code class="descname">STORE_ANNOTATION</code><span class="sig-paren">(</span><em>namei</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-STORE_ANNOTATION" title="Permalink to this definition">¶</a></dt> <dd><p>Stores TOS as <code class="docutils literal notranslate"><span class="pre">locals()['__annotations__'][co_names[namei]]</span> <span class="pre">=</span> <span class="pre">TOS</span></code>.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.6.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-LOAD_CLOSURE"> <code class="descname">LOAD_CLOSURE</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-LOAD_CLOSURE" title="Permalink to this definition">¶</a></dt> <dd><p>Pushes a reference to the cell contained in slot <em>i</em> of the cell and free variable storage. The name of the variable is <code class="docutils literal notranslate"><span class="pre">co_cellvars[i]</span></code> if <em>i</em> is less than the length of <em>co_cellvars</em>. Otherwise it is <code class="docutils literal notranslate"><span class="pre">co_freevars[i</span> <span class="pre">-</span> <span class="pre">len(co_cellvars)]</span></code>.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-LOAD_DEREF"> <code class="descname">LOAD_DEREF</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-LOAD_DEREF" title="Permalink to this definition">¶</a></dt> <dd><p>Loads the cell contained in slot <em>i</em> of the cell and free variable storage. Pushes a reference to the object the cell contains on the stack.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-LOAD_CLASSDEREF"> <code class="descname">LOAD_CLASSDEREF</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-LOAD_CLASSDEREF" title="Permalink to this definition">¶</a></dt> <dd><p>Much like <a class="reference internal" href="#opcode-LOAD_DEREF"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">LOAD_DEREF</span></code></a> but first checks the locals dictionary before consulting the cell. This is used for loading free variables in class bodies.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.4.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-STORE_DEREF"> <code class="descname">STORE_DEREF</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-STORE_DEREF" title="Permalink to this definition">¶</a></dt> <dd><p>Stores TOS into the cell contained in slot <em>i</em> of the cell and free variable storage.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-DELETE_DEREF"> <code class="descname">DELETE_DEREF</code><span class="sig-paren">(</span><em>i</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-DELETE_DEREF" title="Permalink to this definition">¶</a></dt> <dd><p>Empties the cell contained in slot <em>i</em> of the cell and free variable storage. Used by the <a class="reference internal" href="../reference/simple_stmts.html#del"><code class="xref std std-keyword docutils literal notranslate"><span class="pre">del</span></code></a> statement.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.2.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-RAISE_VARARGS"> <code class="descname">RAISE_VARARGS</code><span class="sig-paren">(</span><em>argc</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-RAISE_VARARGS" title="Permalink to this definition">¶</a></dt> <dd><p>Raises an exception. <em>argc</em> indicates the number of arguments to the raise statement, ranging from 0 to 3. The handler will find the traceback as TOS2, the parameter as TOS1, and the exception as TOS.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-CALL_FUNCTION"> <code class="descname">CALL_FUNCTION</code><span class="sig-paren">(</span><em>argc</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-CALL_FUNCTION" title="Permalink to this definition">¶</a></dt> <dd><p>Calls a callable object with positional arguments. <em>argc</em> indicates the number of positional arguments. The top of the stack contains positional arguments, with the right-most argument on top. Below the arguments is a callable object to call. <code class="docutils literal notranslate"><span class="pre">CALL_FUNCTION</span></code> pops all arguments and the callable object off the stack, calls the callable object with those arguments, and pushes the return value returned by the callable object.</p> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 3.6: </span>This opcode is used only for calls with positional arguments.</p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-CALL_FUNCTION_KW"> <code class="descname">CALL_FUNCTION_KW</code><span class="sig-paren">(</span><em>argc</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-CALL_FUNCTION_KW" title="Permalink to this definition">¶</a></dt> <dd><p>Calls a callable object with positional (if any) and keyword arguments. <em>argc</em> indicates the total number of positional and keyword arguments. The top element on the stack contains a tuple of keyword argument names. Below that are keyword arguments in the order corresponding to the tuple. Below that are positional arguments, with the right-most parameter on top. Below the arguments is a callable object to call. <code class="docutils literal notranslate"><span class="pre">CALL_FUNCTION_KW</span></code> pops all arguments and the callable object off the stack, calls the callable object with those arguments, and pushes the return value returned by the callable object.</p> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 3.6: </span>Keyword arguments are packed in a tuple instead of a dictionary, <em>argc</em> indicates the total number of arguments.</p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-CALL_FUNCTION_EX"> <code class="descname">CALL_FUNCTION_EX</code><span class="sig-paren">(</span><em>flags</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-CALL_FUNCTION_EX" title="Permalink to this definition">¶</a></dt> <dd><p>Calls a callable object with variable set of positional and keyword arguments. If the lowest bit of <em>flags</em> is set, the top of the stack contains a mapping object containing additional keyword arguments. Below that is an iterable object containing positional arguments and a callable object to call. <a class="reference internal" href="#opcode-BUILD_MAP_UNPACK_WITH_CALL"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_MAP_UNPACK_WITH_CALL</span></code></a> and <a class="reference internal" href="#opcode-BUILD_TUPLE_UNPACK_WITH_CALL"><code class="xref std std-opcode docutils literal notranslate"><span class="pre">BUILD_TUPLE_UNPACK_WITH_CALL</span></code></a> can be used for merging multiple mapping objects and iterables containing arguments. Before the callable is called, the mapping object and iterable object are each “unpacked” and their contents passed in as keyword and positional arguments respectively. <code class="docutils literal notranslate"><span class="pre">CALL_FUNCTION_EX</span></code> pops all arguments and the callable object off the stack, calls the callable object with those arguments, and pushes the return value returned by the callable object.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.6.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-MAKE_FUNCTION"> <code class="descname">MAKE_FUNCTION</code><span class="sig-paren">(</span><em>argc</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-MAKE_FUNCTION" title="Permalink to this definition">¶</a></dt> <dd><p>Pushes a new function object on the stack. From bottom to top, the consumed stack must consist of values if the argument carries a specified flag value</p> <ul class="simple"> <li><code class="docutils literal notranslate"><span class="pre">0x01</span></code> a tuple of default values for positional-only and positional-or-keyword parameters in positional order</li> <li><code class="docutils literal notranslate"><span class="pre">0x02</span></code> a dictionary of keyword-only parameters’ default values</li> <li><code class="docutils literal notranslate"><span class="pre">0x04</span></code> an annotation dictionary</li> <li><code class="docutils literal notranslate"><span class="pre">0x08</span></code> a tuple containing cells for free variables, making a closure</li> <li>the code associated with the function (at TOS1)</li> <li>the <a class="reference internal" href="../glossary.html#term-qualified-name"><span class="xref std std-term">qualified name</span></a> of the function (at TOS)</li> </ul> </dd></dl> <dl class="opcode"> <dt id="opcode-BUILD_SLICE"> <code class="descname">BUILD_SLICE</code><span class="sig-paren">(</span><em>argc</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-BUILD_SLICE" title="Permalink to this definition">¶</a></dt> <dd><p id="index-0">Pushes a slice object on the stack. <em>argc</em> must be 2 or 3. If it is 2, <code class="docutils literal notranslate"><span class="pre">slice(TOS1,</span> <span class="pre">TOS)</span></code> is pushed; if it is 3, <code class="docutils literal notranslate"><span class="pre">slice(TOS2,</span> <span class="pre">TOS1,</span> <span class="pre">TOS)</span></code> is pushed. See the <a class="reference internal" href="functions.html#slice" title="slice"><code class="xref py py-func docutils literal notranslate"><span class="pre">slice()</span></code></a> built-in function for more information.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-EXTENDED_ARG"> <code class="descname">EXTENDED_ARG</code><span class="sig-paren">(</span><em>ext</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-EXTENDED_ARG" title="Permalink to this definition">¶</a></dt> <dd><p>Prefixes any opcode which has an argument too big to fit into the default two bytes. <em>ext</em> holds two additional bytes which, taken together with the subsequent opcode’s argument, comprise a four-byte argument, <em>ext</em> being the two most-significant bytes.</p> </dd></dl> <dl class="opcode"> <dt id="opcode-FORMAT_VALUE"> <code class="descname">FORMAT_VALUE</code><span class="sig-paren">(</span><em>flags</em><span class="sig-paren">)</span><a class="headerlink" href="#opcode-FORMAT_VALUE" title="Permalink to this definition">¶</a></dt> <dd><p>Used for implementing formatted literal strings (f-strings). Pops an optional <em>fmt_spec</em> from the stack, then a required <em>value</em>. <em>flags</em> is interpreted as follows:</p> <ul class="simple"> <li><code class="docutils literal notranslate"><span class="pre">(flags</span> <span class="pre">&</span> <span class="pre">0x03)</span> <span class="pre">==</span> <span class="pre">0x00</span></code>: <em>value</em> is formatted as-is.</li> <li><code class="docutils literal notranslate"><span class="pre">(flags</span> <span class="pre">&</span> <span class="pre">0x03)</span> <span class="pre">==</span> <span class="pre">0x01</span></code>: call <a class="reference internal" href="stdtypes.html#str" title="str"><code class="xref py py-func docutils literal notranslate"><span class="pre">str()</span></code></a> on <em>value</em> before formatting it.</li> <li><code class="docutils literal notranslate"><span class="pre">(flags</span> <span class="pre">&</span> <span class="pre">0x03)</span> <span class="pre">==</span> <span class="pre">0x02</span></code>: call <a class="reference internal" href="functions.html#repr" title="repr"><code class="xref py py-func docutils literal notranslate"><span class="pre">repr()</span></code></a> on <em>value</em> before formatting it.</li> <li><code class="docutils literal notranslate"><span class="pre">(flags</span> <span class="pre">&</span> <span class="pre">0x03)</span> <span class="pre">==</span> <span class="pre">0x03</span></code>: call <a class="reference internal" href="functions.html#ascii" title="ascii"><code class="xref py py-func docutils literal notranslate"><span class="pre">ascii()</span></code></a> on <em>value</em> before formatting it.</li> <li><code class="docutils literal notranslate"><span class="pre">(flags</span> <span class="pre">&</span> <span class="pre">0x04)</span> <span class="pre">==</span> <span class="pre">0x04</span></code>: pop <em>fmt_spec</em> from the stack and use it, else use an empty <em>fmt_spec</em>.</li> </ul> <p>Formatting is performed using <code class="xref c c-func docutils literal notranslate"><span class="pre">PyObject_Format()</span></code>. The result is pushed on the stack.</p> <div class="versionadded"> <p><span class="versionmodified">New in version 3.6.</span></p> </div> </dd></dl> <dl class="opcode"> <dt id="opcode-HAVE_ARGUMENT"> <code class="descname">HAVE_ARGUMENT</code><a class="headerlink" href="#opcode-HAVE_ARGUMENT" title="Permalink to this definition">¶</a></dt> <dd><p>This is not really an opcode. It identifies the dividing line between opcodes which don’t use their argument and those that do (<code class="docutils literal notranslate"><span class="pre"><</span> <span class="pre">HAVE_ARGUMENT</span></code> and <code class="docutils literal notranslate"><span class="pre">>=</span> <span class="pre">HAVE_ARGUMENT</span></code>, respectively).</p> <div class="versionchanged"> <p><span class="versionmodified">Changed in version 3.6: </span>Now every instruction has an argument, but opcodes <code class="docutils literal notranslate"><span class="pre"><</span> <span class="pre">HAVE_ARGUMENT</span></code> ignore it. Before, only opcodes <code class="docutils literal notranslate"><span class="pre">>=</span> <span class="pre">HAVE_ARGUMENT</span></code> had an argument.</p> </div> </dd></dl> </div> <div class="section" id="opcode-collections"> <span id="id1"></span><h2>32.12.4. Opcode collections<a class="headerlink" href="#opcode-collections" title="Permalink to this headline">¶</a></h2> <p>These collections are provided for automatic introspection of bytecode instructions:</p> <dl class="data"> <dt id="dis.opname"> <code class="descclassname">dis.</code><code class="descname">opname</code><a class="headerlink" href="#dis.opname" title="Permalink to this definition">¶</a></dt> <dd><p>Sequence of operation names, indexable using the bytecode.</p> </dd></dl> <dl class="data"> <dt id="dis.opmap"> <code class="descclassname">dis.</code><code class="descname">opmap</code><a class="headerlink" href="#dis.opmap" title="Permalink to this definition">¶</a></dt> <dd><p>Dictionary mapping operation names to bytecodes.</p> </dd></dl> <dl class="data"> <dt id="dis.cmp_op"> <code class="descclassname">dis.</code><code class="descname">cmp_op</code><a class="headerlink" href="#dis.cmp_op" title="Permalink to this definition">¶</a></dt> <dd><p>Sequence of all compare operation names.</p> </dd></dl> <dl class="data"> <dt id="dis.hasconst"> <code class="descclassname">dis.</code><code class="descname">hasconst</code><a class="headerlink" href="#dis.hasconst" title="Permalink to this definition">¶</a></dt> <dd><p>Sequence of bytecodes that access a constant.</p> </dd></dl> <dl class="data"> <dt id="dis.hasfree"> <code class="descclassname">dis.</code><code class="descname">hasfree</code><a class="headerlink" href="#dis.hasfree" title="Permalink to this definition">¶</a></dt> <dd><p>Sequence of bytecodes that access a free variable (note that ‘free’ in this context refers to names in the current scope that are referenced by inner scopes or names in outer scopes that are referenced from this scope. It does <em>not</em> include references to global or builtin scopes).</p> </dd></dl> <dl class="data"> <dt id="dis.hasname"> <code class="descclassname">dis.</code><code class="descname">hasname</code><a class="headerlink" href="#dis.hasname" title="Permalink to this definition">¶</a></dt> <dd><p>Sequence of bytecodes that access an attribute by name.</p> </dd></dl> <dl class="data"> <dt id="dis.hasjrel"> <code class="descclassname">dis.</code><code class="descname">hasjrel</code><a class="headerlink" href="#dis.hasjrel" title="Permalink to this definition">¶</a></dt> <dd><p>Sequence of bytecodes that have a relative jump target.</p> </dd></dl> <dl class="data"> <dt id="dis.hasjabs"> <code class="descclassname">dis.</code><code class="descname">hasjabs</code><a class="headerlink" href="#dis.hasjabs" title="Permalink to this definition">¶</a></dt> <dd><p>Sequence of bytecodes that have an absolute jump target.</p> </dd></dl> <dl class="data"> <dt id="dis.haslocal"> <code class="descclassname">dis.</code><code class="descname">haslocal</code><a class="headerlink" href="#dis.haslocal" title="Permalink to this definition">¶</a></dt> <dd><p>Sequence of bytecodes that access a local variable.</p> </dd></dl> <dl class="data"> <dt id="dis.hascompare"> <code class="descclassname">dis.</code><code class="descname">hascompare</code><a class="headerlink" href="#dis.hascompare" title="Permalink to this definition">¶</a></dt> <dd><p>Sequence of bytecodes of Boolean operations.</p> </dd></dl> </div> </div> </div> </div> </div> <div class="sphinxsidebar" role="navigation" aria-label="main navigation"> <div class="sphinxsidebarwrapper"> <h3><a href="../contents.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">32.12. <code class="docutils literal notranslate"><span class="pre">dis</span></code> — Disassembler for Python bytecode</a><ul> <li><a class="reference internal" href="#bytecode-analysis">32.12.1. Bytecode analysis</a></li> <li><a class="reference internal" href="#analysis-functions">32.12.2. Analysis functions</a></li> <li><a class="reference internal" href="#python-bytecode-instructions">32.12.3. Python Bytecode Instructions</a></li> <li><a class="reference internal" href="#opcode-collections">32.12.4. Opcode collections</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="compileall.html" title="previous chapter">32.11. <code class="docutils literal notranslate"><span class="pre">compileall</span></code> — Byte-compile Python libraries</a></p> <h4>Next topic</h4> <p class="topless"><a href="pickletools.html" title="next chapter">32.13. <code class="docutils literal notranslate"><span class="pre">pickletools</span></code> — Tools for pickle developers</a></p> <div role="note" aria-label="source link"> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../bugs.html">Report a Bug</a></li> <li> <a href="https://github.com/python/cpython/blob/3.6/Doc/library/dis.rst" rel="nofollow">Show Source </a> </li> </ul> </div> </div> </div> <div class="clearer"></div> </div> <div class="related" role="navigation" aria-label="related navigation"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="pickletools.html" title="32.13. pickletools — Tools for pickle developers" >next</a> |</li> <li class="right" > <a href="compileall.html" title="32.11. compileall — Byte-compile Python libraries" >previous</a> |</li> <li><img src="../_static/py.png" alt="" style="vertical-align: middle; margin-top: -1px"/></li> <li><a href="https://www.python.org/">Python</a> »</li> <li> <a href="../index.html">3.6.7 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" >32. Python Language Services</a> »</li> <li class="right"> <div class="inline-search" style="display: none" role="search"> <form class="inline-search" action="../search.html" method="get"> <input placeholder="Quick search" type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> </div> <script type="text/javascript">$('.inline-search').show(0);</script> | </li> </ul> </div> <div class="footer"> © <a href="../copyright.html">Copyright</a> 2001-2023, Python Software Foundation. <br /> The Python Software Foundation is a non-profit corporation. <a href="https://www.python.org/psf/donations/">Please donate.</a> <br /> Last updated on Dec 18, 2023. <a href="../bugs.html">Found a bug</a>? <br /> Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.7.6. </div> </body> </html>
Save
cmd:
run