Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mode/utils/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 13 additions & 9 deletions tests/unit/utils/test_objects.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import abc
import collections.abc
import pickle
import sys
import typing
from typing import (
AbstractSet,
Expand Down Expand Up @@ -377,14 +378,17 @@ def test_label_pass():
assert label(s) is s


@pytest.mark.parametrize(
"input,expected",
[
(str, False),
(int, False),
(Union[int, bytes], True),
(Optional[str], True),
],
)
IS_UNION_CASES = [
(str, False),
(int, False),
(Union[int, bytes], True),
(Optional[str], True),
]
if sys.version_info >= (3, 10):
# X | Y syntax is only usable at runtime on Python 3.10+
IS_UNION_CASES.append((int | None, True))


@pytest.mark.parametrize("input,expected", IS_UNION_CASES)
def test_is_union(input, expected):
assert is_union(input) == expected
Loading