Bytecode

Latest version: v0.16.1

Safety actively analyzes 723158 Python packages for vulnerabilities to keep your Python projects secure.

Scan your dependencies

Page 3 of 4

0.8.0

-------------------------

New features:

- Add support for Python 3.7 PR 29
- Add preliminary support for Python 3.8-dev PR 41
- Allow to use any Python object as constants to enable aggressive
optimizations PR 34

API changes:

- `stack_effect` is now a method of :class:`Instr` and not as property anymore. PR 29

Bugfixes:

- Avoid throwing `OverflowError` when applying `stack_effect` on valid :class:`Instr`
objects. PR 43, PR 44

0.7.0

-------------------------

New features:

- Add `compute_jumps_passes` optional argument to :meth:`Bytecode.to_code` and
to :meth:`Bytecode.to_concrete_bytecode` to control the number of passes
performed to compute jump targets. In theory the required number is only
bounded by the size of the code, but usually the algorithm converges quickly
(< 10 iterations).

Bugfixes:

- proper handling of `EXTENDED_ARG` without arguments PR 28:

`EXTENDED_ARG` are once again removed but their presence is recorded to avoid
having issues with offsets in jumps. Similarly when round tripping code
through :class:`ConcreteBytecode` the `EXTENDED_ARG` without args are
preserved while if going through :class:`Bytecode` they are removed.

0.6

-----------------------

* Add stack depth computation based on control flow graph analysis
* Add higher level flags handling using IntFlags enum and inference function
* Add an instructions argument to ConcreteBytecode, and validate its value
* Do not delete `EXTENDED_ARG` instructions that have no arg

0.5

-----------------------

* Add the new bytecode format of Python 3.6.
* Remove the ``BaseInstr`` class which became useless. It was replaced
with the :class:`Instr` class.
* Documentation: Add a comparison with byteplay and codetransformer.
* Remove the BaseIntr class: Instr becomes the new base class.
* Fix PEP 8 issues and check PEP 8 on Travis CI.

0.4

-----------------------

Peephole optimizer:

* Reenable optimization on ``JUMP_IF_TRUE_OR_POP`` jumping to
``POP_JUMP_IF_FALSE <target>``.

0.3

-----------------------

New features:

- Add :meth:`ControlFlowGraph.get_block_index` method

API changes:

- Rename ``Block`` class to :class:`BasicBlock`
- Rename ``BytecodeBlocks`` class to :class:`ControlFlowGraph`
- Rename ``BaseInstr.op`` to :attr:`BaseInstr.opcode`
- Rename ``BaseBytecode.kw_only_argcount`` attribute to
:attr:`BaseBytecode.kwonlyargcount`, name closer to the Python code object
attribute (``co_kwonlyargcount``)
- :class:`Instr` constructor and its :meth:`~BaseInstr.set` method now
validates the argument type
- Add :class:`Compare` enum, used for ``COMPARE_OP`` argument of :class:`Instr`
- Remove *lineno* parameter from the :meth:`BaseInstr.set` method
- Add :class:`CellVar` and :class:`FreeVar` classes: instructions having
a cell or free variable now require a :class:`CellVar` or :class:`FreeVar`
instance rather than a simple string (``str``). This change is required
to handle correctly code with duplicated variable names in cell and free
variables.
- :class:`ControlFlowGraph`: remove undocumented ``to_concrete_bytecode()``
and ``to_code()`` methods

Bugfixes:

- Fix support of :class:`SetLineno`

Peephole optimizer:

- Better code for LOAD_CONST x n + BUILD_LIST + UNPACK_SEQUENCE: rewrite
LOAD_CONST in the reverse order instead of using ROT_TWO and ROT_THREE.
This optimization supports more than 3 items.
- Remove JUMP_ABSOLUTE pointing to the following code. It can occur
after dead code was removed.
- Remove NOP instructions
- Bugfix: catch IndexError when trying to get the next instruction.

Page 3 of 4

© 2025 Safety CLI Cybersecurity Inc. All Rights Reserved.