diff --git a/pydra/engine/core.py b/pydra/engine/core.py index 31127cac9..c502aec64 100644 --- a/pydra/engine/core.py +++ b/pydra/engine/core.py @@ -10,7 +10,7 @@ from copy import deepcopy from uuid import uuid4 -import cloudpickle as cp +import cloudpickle as cp # type: ignore[import] from filelock import SoftFileLock import shutil from tempfile import mkdtemp diff --git a/pydra/engine/helpers.py b/pydra/engine/helpers.py index d455a2115..99f839e47 100644 --- a/pydra/engine/helpers.py +++ b/pydra/engine/helpers.py @@ -2,7 +2,7 @@ import asyncio import asyncio.subprocess as asp import attr -import cloudpickle as cp +import cloudpickle as cp # type: ignore[import] from pathlib import Path from filelock import SoftFileLock, Timeout import os diff --git a/pydra/engine/specs.py b/pydra/engine/specs.py index 703368474..549d1fff7 100644 --- a/pydra/engine/specs.py +++ b/pydra/engine/specs.py @@ -8,6 +8,8 @@ from .helpers_file import template_update_single +T = ty.TypeVar("T") + def attr_fields(spec, exclude_names=()): return [field for field in spec.__attrs_attrs__ if field.name not in exclude_names] @@ -21,15 +23,15 @@ def attr_fields_dict(spec, exclude_names=()): } -class File: - """An :obj:`os.pathlike` object, designating a file.""" +File = ty.NewType("File", Path) +"""An :obj:`os.pathlike` object, designating a file.""" -class Directory: - """An :obj:`os.pathlike` object, designating a folder.""" +Directory = ty.NewType("Directory", Path) +"""An :obj:`os.pathlike` object, designating a folder.""" -class MultiInputObj: +class MultiInputObj(ty.Generic[T]): """A ty.List[ty.Any] object, converter changes a single values to a list""" @classmethod @@ -42,7 +44,7 @@ def converter(cls, value): return ensure_list(value) -class MultiOutputObj: +class MultiOutputObj(ty.Generic[T]): """A ty.List[ty.Any] object, converter changes an 1-el list to the single value""" @classmethod @@ -53,11 +55,11 @@ def converter(cls, value): return value -class MultiInputFile(MultiInputObj): +class MultiInputFile(MultiInputObj[File]): """A ty.List[File] object, converter changes a single file path to a list""" -class MultiOutputFile(MultiOutputObj): +class MultiOutputFile(MultiOutputObj[File]): """A ty.List[File] object, converter changes an 1-el list to the single value""" diff --git a/pydra/engine/task.py b/pydra/engine/task.py index c6125fbad..a83e37007 100644 --- a/pydra/engine/task.py +++ b/pydra/engine/task.py @@ -41,7 +41,7 @@ import platform import re import attr -import cloudpickle as cp +import cloudpickle as cp # type: ignore[import] import inspect import typing as ty import shlex diff --git a/pydra/engine/tests/test_helpers.py b/pydra/engine/tests/test_helpers.py index efceeb675..a02e403ea 100644 --- a/pydra/engine/tests/test_helpers.py +++ b/pydra/engine/tests/test_helpers.py @@ -5,7 +5,7 @@ import platform import pytest -import cloudpickle as cp +import cloudpickle as cp # type: ignore[import] from .utils import multiply, raise_xeq1 from ..helpers import ( diff --git a/pydra/engine/tests/test_task.py b/pydra/engine/tests/test_task.py index 2762bcf95..24e3f49ec 100644 --- a/pydra/engine/tests/test_task.py +++ b/pydra/engine/tests/test_task.py @@ -2,7 +2,7 @@ import os, sys import attr import pytest -import cloudpickle as cp +import cloudpickle as cp # type: ignore[import] from pathlib import Path import re import json diff --git a/pydra/utils/messenger.py b/pydra/utils/messenger.py index b1c587153..3209067c5 100644 --- a/pydra/utils/messenger.py +++ b/pydra/utils/messenger.py @@ -182,7 +182,7 @@ def collect_messages(collected_path, message_path, ld_op="compact"): Option used by pld.jsonld """ - import pyld as pld + import pyld as pld # type: ignore[import] import json from glob import glob diff --git a/pyproject.toml b/pyproject.toml index ce7eb465d..48cb10182 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,7 @@ dask = [ ] dev = [ "black", + "mypy", "pre-commit", "pydra[test]", ] @@ -101,3 +102,9 @@ exclude = "pydra/_version.py" [tool.codespell] ignore-words = ".codespell-ignorewords" + +[tool.mypy] +warn_unused_configs = true +warn_redundant_casts = true +warn_unused_ignores = true +no_implicit_optional = true