pleroma
Core module containing MergeableMixin.
pleroma.mergeable.MergeableMixin
Mixin that adds merge capabilities to dataclasses.
Subclass this alongside @dataclasses.dataclass to gain merge and
merged_with class and instance methods. The merge strategy can be
customised by overriding _iter_instances (traversal order / filtering)
and _merge_two (field-level resolution).
merge(instances, *, overwrite_none=False)
classmethod
Merges a collection of instances into a single instance.
Instances are traversed in the order returned by :meth:_iter_instances
and then folded pairwise using :meth:_merge_two.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
instances
|
Collection[Self]
|
The instances to merge. Must be non-empty after
:meth: |
required |
overwrite_none
|
bool
|
Forwarded to each :meth: |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A new merged instance of this class. |
Raises:
| Type | Description |
|---|---|
ValueError
|
When the effective instance list is empty. |
merged_with(*others, overwrite_none=False)
Merges this instance with additional instances.
Equivalent to calling :meth:merge on this class with self prepended
to others.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
others
|
Self
|
Additional instances to merge. |
()
|
overwrite_none
|
bool
|
Forwarded to :meth: |
False
|
Returns:
| Type | Description |
|---|---|
Self
|
A new merged instance. |