What does RESUME opcode actually do?

104 Views Asked by At

The documentation is not very informative (at least for me):

opcode:: RESUME (context)

A no-op. Performs internal tracing, debugging and optimization checks.

The context oparand consists of two parts. The lowest two bits indicate where the RESUME occurs:

  • 0 The start of a function, which is neither a generator, coroutine nor an async generator

  • 1 After a yield expression

  • 2 After a yield from expression

  • 3 After an await expression

The next bit is 1 if the RESUME is at except-depth 1, and 0 otherwise.

Example:

>>> import dis
>>> 
>>> def f(): ...
... 
>>> dis.dis(f)
  1           0 RESUME                   0
              2 LOAD_CONST               0 (None)
              4 RETURN_VALUE

Can someone provide an explanation of what this opcode really does?

0

There are 0 best solutions below