From 6659c307b03129e060456323030b9e989195e07a Mon Sep 17 00:00:00 2001 From: njabulo ndlovu Date: Fri, 4 Apr 2025 19:50:55 +0200 Subject: [PATCH] fix: update is_union function to support python 3.10+ union syntax --- mode/utils/objects.py | 1 + tests/unit/utils/test_objects.py | 1 + 2 files changed, 2 insertions(+) diff --git a/mode/utils/objects.py b/mode/utils/objects.py index 8c197dc..1d780ba 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 4ae4081..6b11748 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):