Enables increment operators in Python with a bytecode hack

PyPI version CI status Codecov

Enable ++x and --x expressions in Python

What’s this?

By default, Python supports neither pre-increments (like ++x) nor post-increments (like x++). However, the first ones are syntactically correct since Python parses them as two subsequent +x operations, where + is the unary plus operator (same with --x and the unary minus). They both have no effect, since in practice -(-x) == +(+x) == x.

This module turns the ++x-like expressions into x += 1 at the bytecode level. Increments and decrements of collection items and object attributes are supported as well, for example: