snakeoil.klass.deprecated module

Implementations of immutable instance metaclasses

class snakeoil.klass.deprecated.ImmutableInstance(**kwargs)[source]

Bases: object

Class that disables surface-level attribute modifications.

snakeoil.klass.deprecated.immutable_instance(name: str, bases: tuple[type], scope: dict[str, ~typing.Any], real_type=<class 'type'>) type[source]

metaclass that makes instances of this class effectively immutable

It still is possible to do object.__setattr__ to get around it during initialization, but usage of this class effectively prevents accidental modification, instead requiring explicit modification.

snakeoil.klass.deprecated.inject_immutable_instance(scope: dict[str, Any])[source]

inject immutable __setattr__ and __delattr__ implementations

see immutable_instance for further details

Parameters:

scope – mapping to modify, inserting __setattr__ and __delattr__ methods if they’re not yet defined.