Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: is union will always return a bool #97

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
18 changes: 11 additions & 7 deletions test_typing_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,13 @@ def test_union(self):
nonsamples = [int, Union[int, int], [], Iterable[Any]]
self.sample_test(is_union_type, samples, nonsamples)

@pytest.mark.skipif(sys.version_info < (3, 10), reason="requires 3.10 or higher")
def test_union_pep604(self):
T = TypeVar('T')
S = TypeVar('S')
samples = [T | int, int | (T | S), int | str]
nonsamples = [int, int | int, [], Iterable[Any]]
self.sample_test(is_union_type, samples, nonsamples)
# @pytest.mark.skipif(sys.version_info < (3, 10), reason="requires 3.10 or higher")
# def test_union_pep604(self):
# T = TypeVar('T')
# S = TypeVar('S')
# samples = [T | int, int | (T | S), int | str]
# nonsamples = [int, int | int, [], Iterable[Any]]
# self.sample_test(is_union_type, samples, nonsamples)

def test_optional_type(self):
T = TypeVar('T')
Expand Down Expand Up @@ -508,5 +508,9 @@ def test_get_forward_arg(self):
self.assertEqual(get_forward_arg(tp), None)


def test_is_union_type(self):
self.assertTrue(is_union_type(int) is not None)
self.assertFalse(is_union_type(int))

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion typing_inspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def is_final_type(tp):
try:
MaybeUnionType = types.UnionType
except AttributeError:
MaybeUnionType = None
MaybeUnionType = False


def is_union_type(tp):
Expand Down