diff --git a/mode/utils/objects.py b/mode/utils/objects.py index 70c73c3..8524841 100644 --- a/mode/utils/objects.py +++ b/mode/utils/objects.py @@ -472,6 +472,7 @@ def is_union(typ: Type) -> bool: name = typ.__class__.__name__ return any( [ + name == "UnionType", # 3.10 name == "_UnionGenericAlias", # 3.9 name == "_GenericAlias" and typ.__origin__ is typing.Union, # 3.7 name == "_Union", # 3.6 diff --git a/tests/unit/utils/test_objects.py b/tests/unit/utils/test_objects.py index 0e384af..a62f979 100644 --- a/tests/unit/utils/test_objects.py +++ b/tests/unit/utils/test_objects.py @@ -384,6 +384,7 @@ def test_label_pass(): (int, False), (Union[int, bytes], True), (Optional[str], True), + (int | None, True), ], ) def test_is_union(input, expected):