hikari.internal.attr_extensions#

Utility for extending and optimising the usage of attr models.

Module Contents#

hikari.internal.attr_extensions.invalidate_shallow_copy_cache()[source]#

Remove all the globally cached copy functions.

hikari.internal.attr_extensions.invalidate_deep_copy_cache()[source]#

Remove all the globally cached generated deep copy functions.

hikari.internal.attr_extensions.copy_attrs(model)[source]#

Shallow copy an attrs model with init enabled.

Parameters
modelModelT

The attrs model to shallow copy.

Returns
ModelT

The new shallow copied attrs model.

hikari.internal.attr_extensions.deep_copy_attrs(model, memo=None)[source]#

Deep copy an attrs model with init enabled.

Note

This won’t deep copy attributes where “skip_deep_copy” is set to True in their metadata.

Parameters
modelModelT

The attrs model to deep copy.

memotyping.Optional[typing.MutableMapping[int, typing.Any]]

A memo dictionary of objects already copied during the current copying pass, see <https://docs.python.org/3/library/copy.html> for more details.

Returns
ModelT

The new deep copied attrs model.

hikari.internal.attr_extensions.with_copy(cls)[source]#

Add a custom implementation for copying attrs models to a class.

Note

This will only work if the class has an attrs generated init.