Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: Type-annotate Pydra #648

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pydra/engine/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pydra/engine/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
18 changes: 10 additions & 8 deletions pydra/engine/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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"""


Expand Down
2 changes: 1 addition & 1 deletion pydra/engine/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pydra/engine/tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion pydra/engine/tests/test_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion pydra/utils/messenger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ dask = [
]
dev = [
"black",
"mypy",
"pre-commit",
"pydra[test]",
]
Expand Down Expand Up @@ -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