Skip to content

Commit 6658d1a

Browse files
committed
fix ty check in docs conf
1 parent 88519e7 commit 6658d1a

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

docs/source/conf.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,14 @@
1414
from importlib.metadata import version
1515
from pathlib import Path
1616
from typing import TYPE_CHECKING
17+
from typing import Any
18+
from typing import cast
1719

1820
import pytask_parallel
1921

2022
if TYPE_CHECKING:
23+
from collections.abc import Callable
24+
2125
import sphinx # ty: ignore[unresolved-import]
2226

2327

@@ -100,7 +104,9 @@
100104

101105

102106
# Linkcode, based on numpy doc/source/conf.py
103-
def linkcode_resolve(domain: str, info: dict[str, str]) -> str | None: # noqa: C901
107+
def linkcode_resolve( # noqa: C901, PLR0911
108+
domain: str, info: dict[str, str]
109+
) -> str | None:
104110
"""Determine the URL corresponding to Python object."""
105111
if domain != "py":
106112
return None
@@ -122,11 +128,13 @@ def linkcode_resolve(domain: str, info: dict[str, str]) -> str | None: # noqa:
122128
except AttributeError: # noqa: PERF203
123129
return None
124130

125-
try:
126-
fn = inspect.getsourcefile(inspect.unwrap(obj))
127-
except TypeError:
128-
fget = getattr(obj, "fget", None)
129-
fn = None if fget is None else inspect.getsourcefile(inspect.unwrap(fget))
131+
obj_for_source = obj if callable(obj) else getattr(obj, "fget", None)
132+
if not callable(obj_for_source):
133+
return None
134+
135+
fn = inspect.getsourcefile(
136+
inspect.unwrap(cast("Callable[..., Any]", obj_for_source))
137+
)
130138
if not fn:
131139
return None
132140

0 commit comments

Comments
 (0)