Skip to content

Commit 252c37b

Browse files
[pre-commit.ci] pre-commit autoupdate (#120)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/pre-commit/pre-commit-hooks: v5.0.0 → v6.0.0](pre-commit/pre-commit-hooks@v5.0.0...v6.0.0) - [github.com/astral-sh/ruff-pre-commit: v0.12.4 → v0.14.10](astral-sh/ruff-pre-commit@v0.12.4...v0.14.10) - [github.com/kynan/nbstripout: 0.8.1 → 0.8.2](kynan/nbstripout@0.8.1...0.8.2) - [github.com/executablebooks/mdformat: 0.7.22 → 1.0.0](hukkin/mdformat@0.7.22...1.0.0) - [github.com/executablebooks/mdformat: 0.7.22 → 1.0.0](hukkin/mdformat@0.7.22...1.0.0) * Fix ty warnings in docs and wrappers * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * fix ty check in docs conf --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tobias Raabe <raabe@posteo.de>
1 parent d985340 commit 252c37b

3 files changed

Lines changed: 33 additions & 16 deletions

File tree

docs/source/conf.py

Lines changed: 24 additions & 12 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,29 +128,35 @@ 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)) # ty: ignore[invalid-argument-type]
127-
except TypeError:
128-
try: # property
129-
fn = inspect.getsourcefile(inspect.unwrap(obj.fget)) # ty: ignore[possibly-unbound-attribute,invalid-argument-type]
130-
except (AttributeError, TypeError):
131-
fn = None
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+
)
132138
if not fn:
133139
return None
134140

135141
try:
136142
source, lineno = inspect.getsourcelines(obj)
137143
except TypeError:
138-
try: # property
139-
source, lineno = inspect.getsourcelines(obj.fget) # ty: ignore[possibly-unbound-attribute]
140-
except (AttributeError, TypeError):
144+
fget = getattr(obj, "fget", None)
145+
if fget is None:
141146
lineno = None
147+
else:
148+
try:
149+
source, lineno = inspect.getsourcelines(fget)
150+
except TypeError:
151+
lineno = None
142152
except OSError:
143153
lineno = None
144154

145155
linespec = f"#L{lineno}-L{lineno + len(source) - 1}" if lineno else ""
146156

147-
fn = os.path.relpath(fn, start=Path(pytask_parallel.__file__).parent) # ty: ignore[invalid-argument-type]
157+
package_file = pytask_parallel.__file__
158+
package_root = Path(package_file).parent if package_file else Path.cwd()
159+
fn = os.path.relpath(fn, start=package_root)
148160

149161
if "+" in pytask_parallel.__version__:
150162
return f"https://github.com/pytask-dev/pytask-parallel/blob/main/src/pytask_parallel/{fn}{linespec}"

src/pytask_parallel/execute.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import time
77
from typing import TYPE_CHECKING
88
from typing import Any
9+
from typing import cast
910

1011
import cloudpickle
1112
from _pytask.node_protocols import PPathNode
@@ -209,7 +210,7 @@ def pytask_execute_task(session: Session, task: PTask) -> Future[WrapperResult]:
209210
task_module = get_module(task.function, getattr(task, "path", None))
210211
cloudpickle.register_pickle_by_value(task_module)
211212

212-
return wrapper_func.submit( # ty: ignore[possibly-unbound-attribute,invalid-return-type]
213+
return cast("Any", wrapper_func).submit(
213214
task=task,
214215
console_options=console.options,
215216
kwargs=kwargs,

src/pytask_parallel/wrappers.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from pathlib import Path
1414
from typing import TYPE_CHECKING
1515
from typing import Any
16+
from typing import cast
1617

1718
from attrs import define
1819
from pytask import PNode
@@ -35,6 +36,7 @@
3536
from pytask_parallel.utils import CoiledFunction
3637

3738
if TYPE_CHECKING:
39+
from collections.abc import Callable
3840
from types import TracebackType
3941

4042
from pytask import Mark
@@ -168,9 +170,11 @@ def wrap_task_in_process( # noqa: PLR0913
168170

169171

170172
def rewrap_task_with_coiled_function(task: PTask) -> CoiledFunction:
171-
return functools.wraps(wrap_task_in_process)( # ty: ignore[invalid-return-type]
172-
CoiledFunction(wrap_task_in_process, **task.attributes["coiled_kwargs"]) # ty: ignore[invalid-argument-type]
173+
wrapped = CoiledFunction(wrap_task_in_process, **task.attributes["coiled_kwargs"])
174+
decorated = functools.wraps(wrap_task_in_process)(
175+
cast("Callable[..., Any]", wrapped)
173176
)
177+
return cast("CoiledFunction", decorated)
174178

175179

176180
def _raise_exception_on_breakpoint(*args: Any, **kwargs: Any) -> None: # noqa: ARG001
@@ -203,7 +207,7 @@ def _render_traceback_to_string(
203207
) -> tuple[type[BaseException], BaseException, str]:
204208
"""Process the exception and convert the traceback to a string."""
205209
traceback = Traceback(exc_info, show_locals=show_locals)
206-
segments = console.render(traceback, options=console_options) # ty: ignore[invalid-argument-type]
210+
segments = console.render(cast("Any", traceback), options=console_options)
207211
text = "".join(segment.text for segment in segments)
208212
return (*exc_info[:2], text) # ty: ignore[invalid-return-type]
209213

0 commit comments

Comments
 (0)