Skip to content

Commit 5072dda

Browse files
committed
Base AnnotationFactory class
1 parent 063a422 commit 5072dda

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

named_annotations.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from abc import ABC, abstractmethod
2+
3+
4+
class AnnotationFactory(ABC):
5+
"""
6+
Annotation factory class.
7+
Creates annotation by input other.
8+
9+
Can be used via [] (preferred) or by normal call.
10+
"""
11+
12+
def __call__(self, annotation: any) -> any:
13+
return self._create_full_annotation_by(annotation)
14+
15+
def __getitem__(self, annotation: any) -> any:
16+
return self._create_full_annotation_by(
17+
Union[annotation]
18+
if isinstance(annotation, Iterable)
19+
else annotation
20+
)
21+
22+
@abstractmethod
23+
def _create_full_annotation_by(self, annotation: any) -> any:
24+
"""Annotation Creation Method from an input annotation."""
25+
26+

0 commit comments

Comments
 (0)