jangada.serialization.Serializable.copy#

Serializable.copy() Serializable#

Create an independent copy of this object.

Uses serialization with is_copy=True, so only copiable properties are included in the copy.

Returns:
Serializable

A new instance with the same copiable property values.

See also

__copy__

Implements copy.copy() support

Notes

The copy is created via serialization, so: - Only copiable properties are copied - Non-copiable properties use their defaults - Nested objects are also copied (deep copy) - All property initialization (parsers, observers, initializers) runs

Examples

>>> class MyClass(Serializable):
...     value = SerializableProperty(default=0, copiable=True)
...     cache = SerializableProperty(default=0, copiable=False)
...
>>> obj = MyClass(value=42, cache=100)
>>> copied = obj.copy()
>>> copied.value
42
>>> copied.cache
0
>>> copied is obj
False