Skip to content

Commit 56c270d

Browse files
committed
Fix typing regressions after merging main
1 parent 38b3502 commit 56c270d

4 files changed

Lines changed: 13 additions & 8 deletions

File tree

src/pytask_parallel/config.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ def pytask_parse_config(config: dict[str, Any]) -> None:
2727
raise ValueError(msg) from None
2828

2929
if config["n_workers"] == "auto":
30-
config["n_workers"] = max(os.cpu_count() - 1, 1) # type: ignore[operator]
30+
cpu_count = os.cpu_count() or 1
31+
config["n_workers"] = max(cpu_count - 1, 1)
3132

3233
# If more than one worker is used, and no backend is set, use loky.
3334
if config["n_workers"] > 1 and config["parallel_backend"] == ParallelBackend.NONE:

src/pytask_parallel/execute.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def pytask_execute_build(session: Session) -> bool | None: # noqa: C901, PLR091
137137
newly_collected_reports.append(
138138
ExecutionReport.from_task_and_exception(
139139
task,
140-
wrapper_result.exc_info, # type: ignore[arg-type]
140+
cast("Any", wrapper_result.exc_info),
141141
)
142142
)
143143
running_tasks.pop(task_name)
@@ -213,7 +213,7 @@ def pytask_execute_task(session: Session, task: PTask) -> Future[WrapperResult]:
213213
# cloudpickle will pickle it with the function. See cloudpickle#417, pytask#373
214214
# and pytask#374.
215215
task_module = get_module(task.function, getattr(task, "path", None))
216-
if should_pickle_module_by_value(task_module):
216+
if task_module is not None and should_pickle_module_by_value(task_module):
217217
cloudpickle.register_pickle_by_value(task_module)
218218

219219
return cast("Any", wrapper_func).submit(
@@ -237,7 +237,7 @@ def pytask_execute_task(session: Session, task: PTask) -> Future[WrapperResult]:
237237
# cloudpickle will pickle it with the function. See cloudpickle#417, pytask#373
238238
# and pytask#374.
239239
task_module = get_module(task.function, getattr(task, "path", None))
240-
if should_pickle_module_by_value(task_module):
240+
if task_module is not None and should_pickle_module_by_value(task_module):
241241
cloudpickle.register_pickle_by_value(task_module)
242242

243243
return session.config["_parallel_executor"].submit(

src/pytask_parallel/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def _parse_future_exception(
136136
return None if exc is None else (type(exc), exc, exc.__traceback__)
137137

138138

139-
def get_module(func: Callable[..., Any], path: Path | None) -> ModuleType:
139+
def get_module(func: Callable[..., Any], path: Path | None) -> ModuleType | None:
140140
"""Get the module of a python function.
141141
142142
``functools.partial`` obfuscates the module of the function and
@@ -151,8 +151,8 @@ def get_module(func: Callable[..., Any], path: Path | None) -> ModuleType:
151151
func = func.func
152152

153153
if path:
154-
return inspect.getmodule(func, path.as_posix()) # type: ignore[return-value]
155-
return inspect.getmodule(func) # type: ignore[return-value]
154+
return inspect.getmodule(func, path.as_posix())
155+
return inspect.getmodule(func)
156156

157157

158158
def strip_annotation_locals(task: PTask) -> None:

src/pytask_parallel/wrappers.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ def wrap_task_in_process( # noqa: PLR0913
138138
except Exception: # noqa: BLE001
139139
exc_info = sys.exc_info()
140140
processed_exc_info = _render_traceback_to_string(
141-
exc_info, # type: ignore[arg-type]
141+
(
142+
cast("type[BaseException]", exc_info[0]),
143+
cast("BaseException", exc_info[1]),
144+
exc_info[2],
145+
),
142146
show_locals,
143147
console_options,
144148
)

0 commit comments

Comments
 (0)