Skip to content

Commit a627348

Browse files
committed
| support for annotation annotation
1 parent d4cb6d3 commit a627348

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

named_annotations.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ class InputAnnotationAnnotation:
2929
"""
3030
Singleton class for the annotation of the conditional empty space, in which
3131
the input type in the CustomAnnotationFactory should be placed.
32+
33+
Supports | to create Union type.
3234
"""
3335

3436
_instance: Optional[Self] = None
@@ -42,6 +44,12 @@ def __new__(cls, *args, **kwargs):
4244
def __repr__(self) -> str:
4345
return '<input_annotation>'
4446

47+
def __or__(self, other: any) -> Union:
48+
return Union[self, other]
49+
50+
def __ror__(self, other: any) -> Union:
51+
return Union[other, self]
52+
4553

4654
class CustomAnnotationFactory(AnnotationFactory):
4755
"""
@@ -97,6 +105,8 @@ def __get_formatted_annotations_from(self, annotations: Iterable, replacement_an
97105
annotation,
98106
replacement_annotation
99107
)
108+
elif type(annotation) is Union or type(annotation) is type(int | float):
109+
annotation = Union[*self.__get_formatted_annotations_from(annotation.__args__)]
100110

101111
formatted_annotations.append(annotation)
102112

0 commit comments

Comments
 (0)