pickletools.dis()

pickletools.dis(pickle, out=None, memo=None, indentlevel=4)[source]

Produce a symbolic disassembly of a pickle.

‘pickle’ is a file-like object, or string, containing a (at least one) pickle. The pickle is disassembled from the current position, through the first STOP opcode encountered.

Optional arg ‘out’ is a file-like object to which the disassembly is printed. It defaults to sys.stdout.

Optional arg ‘memo’ is a Python dict, used as the pickle’s memo. It may be mutated by dis(), if the pickle contains PUT or BINPUT opcodes. Passing the same memo object to another dis() call then allows disassembly to proceed across multiple pickles that were all created by the same pickler with the same memo. Ordinarily you don’t need to worry about this.

Optional arg indentlevel is the number of blanks by which to indent a new MARK level. It defaults to 4.

In addition to printing the disassembly, some sanity checks are made:

  • All embedded opcode arguments “make sense”.
  • Explicit and implicit pop operations have enough items on the stack.
  • When an opcode implicitly refers to a markobject, a markobject is actually on the stack.
  • A memo entry isn’t referenced before it’s defined.
  • The markobject isn’t stored in the memo.
  • A memo entry isn’t redefined.