Skip to content

Commit fd950d2

Browse files
committed
Support for _UnionGenericAlias as Union type when inserting by annotation
1 parent 08bd63c commit fd950d2

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

pyannotating.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from abc import ABC, abstractmethod
2-
from typing import Union, Iterable, Optional, Self, Mapping, Final
2+
from typing import Union, Iterable, Optional, Self, Mapping, Final, Callable, _UnionGenericAlias
33

44

55
class AnnotationFactory(ABC):
@@ -104,8 +104,13 @@ def __get_formatted_annotations_from(self, annotations: Iterable, replacement_an
104104
annotation,
105105
replacement_annotation
106106
)
107-
elif type(annotation) is Union or type(annotation) is type(int | float):
108-
annotation = Union[*self.__get_formatted_annotations_from(annotation.__args__)]
107+
elif type(annotation) in (Union, _UnionGenericAlias, type(int | float)):
108+
annotation = Union[
109+
*self.__get_formatted_annotations_from(
110+
annotation.__args__,
111+
replacement_annotation
112+
)
113+
]
109114

110115
formatted_annotations.append(annotation)
111116

0 commit comments

Comments
 (0)