Python Bytecode Archeology

(Inspired by byteplay and Raymond Hettinger's old but still intriguing recipe for binding constants at compile time)

When playing with the Python Disassembler, it is useful to know which bytecodes have changed between various versions of the cPython interpreter, and why. For this reason, I performed a bit of archeology on the Mercurial repository and issue database.

Even though the developers warn that the bytecode format may change wildly between versions, in practice the instruction set has been pretty stable: of the 122 opcodes encountered, 72 have existed from version 2.0 all the way to 3.2.

In the following table, the first column shows the name of the opcode. Hover over an opcode to show a description. The second column shows the version(s) in which that opcode was introduced, with links to the revision and the PEP/issue that describes the change if available. The third column shows the version(s) in which the opcode was removed.

Written on May 4, 2011
Filed under