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(typing): update common typing to skip non-existent attributes #10666

Open
wants to merge 5 commits into
base: main
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
6 changes: 5 additions & 1 deletion ibis/common/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,11 @@

if include_properties:
for name in dir(obj):
attr = getattr(obj, name)
try:
attr = getattr(obj, name)
except AttributeError:

Check warning on line 65 in ibis/common/typing.py

View check run for this annotation

Codecov / codecov/patch

ibis/common/typing.py#L65

Added line #L65 was not covered by tests
# What else can be done besides skipping and continuing?
continue

Check warning on line 67 in ibis/common/typing.py

View check run for this annotation

Codecov / codecov/patch

ibis/common/typing.py#L67

Added line #L67 was not covered by tests
if isinstance(attr, property):
annots = _get_type_hints(attr.fget, include_extras=include_extras)
if return_annot := annots.get("return"):
Expand Down
22 changes: 22 additions & 0 deletions ibis/tests/test_typing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from __future__ import annotations

from typing import Any

from ibis.common.typing import get_type_hints


class TestClass:
a: int

@property
def b(self) -> str:
return "test"

Check warning on line 13 in ibis/tests/test_typing.py

View check run for this annotation

Codecov / codecov/patch

ibis/tests/test_typing.py#L13

Added line #L13 was not covered by tests

@property
def c(self) -> Any:
raise AttributeError("Property 'c' raises AttributeError")

Check warning on line 17 in ibis/tests/test_typing.py

View check run for this annotation

Codecov / codecov/patch

ibis/tests/test_typing.py#L17

Added line #L17 was not covered by tests


def test_get_type_hints_with_attribute_error():
hints = get_type_hints(TestClass, include_properties=True)
assert hints == {"a": int, "b": str}

Check warning on line 22 in ibis/tests/test_typing.py

View check run for this annotation

Codecov / codecov/patch

ibis/tests/test_typing.py#L21-L22

Added lines #L21 - L22 were not covered by tests
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is failing because the attribute error isn't raised until accessing an instance property, but the function that extracts these properties operates on classes, not instances.

Loading