#tuple #immutability #python

mutuple

Replace items in Python's immutable tuples

1 stable release

1.0.0 Apr 11, 2024

#2468 in Data structures

MIT license

6KB
64 lines

mutuple

Replace items in Python's "immutable" tuples.

Why?

yolo

How?

We use Rust's PyO3 crate to manipulate tuples directly using the Stable CPython API. Editing tuples can lead to issues but works in practice for limited use cases.

Usage

import mutuple


def test_mutable_tuple():
    """mutuple tuple demo"""
    value = ('read-only', 'tuple')
    mutuple.setitem(value, 0, 'mutable')

    assert value == ('mutable', 'tuple')

Dependencies

~3.5–8MB
~72K SLoC