From d936356616e77713be1ee26b473ccc8a5a49eda8 Mon Sep 17 00:00:00 2001 From: Sami Jaghouar Date: Thu, 5 Jan 2023 13:24:22 +0100 Subject: [PATCH 1/2] fix: is union will always return a bool Signed-off-by: Sami Jaghouar --- test_typing_inspect.py | 17 ++++++++++------- typing_inspect.py | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/test_typing_inspect.py b/test_typing_inspect.py index eaea460..549fb42 100644 --- a/test_typing_inspect.py +++ b/test_typing_inspect.py @@ -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') @@ -508,5 +508,8 @@ 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) + if __name__ == '__main__': main() diff --git a/typing_inspect.py b/typing_inspect.py index 0268b16..0d69208 100644 --- a/typing_inspect.py +++ b/typing_inspect.py @@ -213,7 +213,7 @@ def is_final_type(tp): try: MaybeUnionType = types.UnionType except AttributeError: - MaybeUnionType = None + MaybeUnionType = False def is_union_type(tp): From 2bd3755c5ea16d72c14b8647625f3ac6e54bc24a Mon Sep 17 00:00:00 2001 From: Sami Jaghouar Date: Thu, 5 Jan 2023 13:27:37 +0100 Subject: [PATCH 2/2] fix: ad test for int is union Signed-off-by: Sami Jaghouar --- test_typing_inspect.py | 1 + 1 file changed, 1 insertion(+) diff --git a/test_typing_inspect.py b/test_typing_inspect.py index 549fb42..3f1c587 100644 --- a/test_typing_inspect.py +++ b/test_typing_inspect.py @@ -510,6 +510,7 @@ def test_get_forward_arg(self): 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()