From 5a3ea1c34b16b586f5adc95bf50844d8d20d2d8e Mon Sep 17 00:00:00 2001 From: Kevin Mills <35641675+millsks@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:08:11 -0600 Subject: [PATCH 1/5] Update typing.py Skipping a property if the attribute is not available --- ibis/common/typing.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ibis/common/typing.py b/ibis/common/typing.py index 33da104f4150..79f5fba6c420 100644 --- a/ibis/common/typing.py +++ b/ibis/common/typing.py @@ -60,7 +60,11 @@ class properties. if include_properties: for name in dir(obj): - attr = getattr(obj, name) + try: + attr = getattr(obj, name) + except AttributeError: + # What else can be done besides skipping and continuing? + continue if isinstance(attr, property): annots = _get_type_hints(attr.fget, include_extras=include_extras) if return_annot := annots.get("return"): From 10f23d4dfbbf39402ea2390e5948c12847e56fc8 Mon Sep 17 00:00:00 2001 From: Kevin Mills <35641675+millsks@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:54:58 -0600 Subject: [PATCH 2/5] Create test_typing.py Testing the typing module in ibis.common --- ibis/tests/test_typing.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 ibis/tests/test_typing.py diff --git a/ibis/tests/test_typing.py b/ibis/tests/test_typing.py new file mode 100644 index 000000000000..59c36b12d104 --- /dev/null +++ b/ibis/tests/test_typing.py @@ -0,0 +1,17 @@ +import pytest +from typing import Any + +from ibis.common.typing import get_type_hints + +class TestClass: + a: int + @property + def b(self) -> str: + return "test" + @property + def c(self) -> Any: + raise AttributeError("Property 'c' raises AttributeError") + +def test_get_type_hints_with_attribute_error(): + hints = get_type_hints(TestClass, include_properties=True) + assert hints == {"a": int, "b": str} From 7a0202c6dd5bd9061189923aa4f7e1c9e75da8af Mon Sep 17 00:00:00 2001 From: Kevin Mills <35641675+millsks@users.noreply.github.com> Date: Fri, 10 Jan 2025 14:59:35 -0600 Subject: [PATCH 3/5] Update test_typing.py --- ibis/tests/test_typing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/ibis/tests/test_typing.py b/ibis/tests/test_typing.py index 59c36b12d104..d63f757fcbce 100644 --- a/ibis/tests/test_typing.py +++ b/ibis/tests/test_typing.py @@ -1,4 +1,3 @@ -import pytest from typing import Any from ibis.common.typing import get_type_hints From 2703d4f52d6567fbec673402e439f409e02e0522 Mon Sep 17 00:00:00 2001 From: Kevin Mills <35641675+millsks@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:02:44 -0600 Subject: [PATCH 4/5] Update test_typing.py --- ibis/tests/test_typing.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ibis/tests/test_typing.py b/ibis/tests/test_typing.py index d63f757fcbce..afc8fde08985 100644 --- a/ibis/tests/test_typing.py +++ b/ibis/tests/test_typing.py @@ -1,3 +1,5 @@ +from __future__ import annotations + from typing import Any from ibis.common.typing import get_type_hints From 2827077304cfd9c339f2824ecdf2d69cfdded44a Mon Sep 17 00:00:00 2001 From: Kevin Mills <35641675+millsks@users.noreply.github.com> Date: Fri, 10 Jan 2025 15:07:26 -0600 Subject: [PATCH 5/5] Update test_typing.py --- ibis/tests/test_typing.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ibis/tests/test_typing.py b/ibis/tests/test_typing.py index afc8fde08985..5db9fe180d35 100644 --- a/ibis/tests/test_typing.py +++ b/ibis/tests/test_typing.py @@ -4,15 +4,19 @@ from ibis.common.typing import get_type_hints + class TestClass: a: int + @property def b(self) -> str: return "test" + @property def c(self) -> Any: raise AttributeError("Property 'c' raises AttributeError") + def test_get_type_hints_with_attribute_error(): hints = get_type_hints(TestClass, include_properties=True) assert hints == {"a": int, "b": str}