Skip to content

Commit 2af7193

Browse files
Prevents reaching inner blocks that contains if TYPE_CHECKING
1 parent 01b3a1a commit 2af7193

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

src/sphinx_autodoc_typehints/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def get_all_type_hints(obj: Any, name: str) -> dict[str, Any]:
271271
return _get_type_hint(name, obj)
272272

273273

274-
_TYPE_GUARD_IMPORT_RE = re.compile(r"if (typing.)?TYPE_CHECKING:[^\n]*([\s\S]*?)(?=\n\S)")
274+
_TYPE_GUARD_IMPORT_RE = re.compile(r"\nif (typing.)?TYPE_CHECKING:[^\n]*([\s\S]*?)(?=\n\S)")
275275
_TYPE_GUARD_IMPORTS_RESOLVED = set()
276276

277277

tests/roots/test-resolve-typing-guard/demo_typing_guard.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ def a(f: Decimal, s: AnyStr) -> Sequence[AnyStr | Decimal]:
2929
return [f, s]
3030

3131

32+
class SomeClass:
33+
"""This class do something."""
34+
35+
if TYPE_CHECKING: # Classes doesn't have `__globals__` attribute
36+
37+
def __getattr__(self, item: str): # noqa: U100
38+
"""This method do something."""
39+
40+
3241
__all__ = [
3342
"a",
3443
"ValueError",

0 commit comments

Comments
 (0)