Python Glossary Русский

Python 3.4+disfunction

dis.stack_effect()

code information

Returns how much an opcode changes the depth of the interpreter's evaluation stack: +1, -1 and so on.

Syntax

dis.stack_effect(opcode, oparg=None, *, jump=None)

Opcode numbers differ in every version, so pass dis.opmap['NAME'] rather than a number. Before 3.13 an opcode that takes an argument raised ValueError without oparg; since 3.13 oparg=0 is assumed — pass oparg explicitly so the code works everywhere. For jumps jump=True and jump=False give different values; without jump you get the larger of the two.

Examples

import dis
print(dis.stack_effect(dis.opmap['POP_TOP']))  # → -1
print(dis.stack_effect(dis.opmap['LOAD_CONST'], 0))  # → 1

See also

Common errors

Open in the full glossarydocs.python.orgReport an inaccuracy