Skip to content

Commit b402cc9

Browse files
committed
Annotation creation method for CustomAnnotationFactory
1 parent 795a4d1 commit b402cc9

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

named_annotations.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,28 @@ def _create_full_annotation_by(self, annotation: any) -> any:
6868
*self.__get_formatted_annotations_from(self._annotations, annotation)
6969
]
7070

71+
def __get_formatted_annotations_from(self, annotations: Iterable, replacement_annotation: any) -> tuple:
72+
"""
73+
Recursive function to replace element(s) of the input collection (and
74+
its subcollections) equal to the annotation anonation with the input
75+
annotation.
76+
"""
77+
78+
formatted_annotations = list()
79+
80+
for annotation in annotations:
81+
if annotation == self.input_annotation_annotation:
82+
annotation = replacement_annotation
83+
elif isinstance(annotation, Iterable) and not isinstance(annotation, str):
84+
annotation = self.__get_formatted_annotations_from(
85+
annotation,
86+
replacement_annotation
87+
)
88+
89+
formatted_annotations.append(annotation)
90+
91+
return tuple(formatted_annotations)
92+
7193
def __recursively_format(self, collection: Iterable) -> list:
7294
"""
7395
Method for formatting the elements of a collection (and all of its

0 commit comments

Comments
 (0)