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

Add type hint for @job and fix for run_locally #578

Merged
merged 9 commits into from
Apr 3, 2024

Conversation

FabiPi3
Copy link
Contributor

@FabiPi3 FabiPi3 commented Apr 3, 2024

Since mypy deprecates the implicit use of None for default values, add the explicit None type hint for store in the run_locally method.

The @job decorator is supposed to transform anything into a Job, I think my change is the minimal effort to take to convince type checkers like mypy or pycharm integrated tools that the result will be a Job. Consider the following examples:

def add(a: int, b: int) -> int:
    """Add func."""
    return a + b

@job
def add_job(a: int, b: int) -> int:
    """Add job."""
    return a + b

@job(large_data="data", graphs="graph")
def compute(a: int, b: int) -> dict[str, int]:
    """Compute job."""
    return {"data": b, "graph": a}

reveal_type(add(1, 2))
reveal_type(add_job(1, 2))
reveal_type(compute(1, 2))

Running mypy over this leads to:

mypy_example.py:15: note: Revealed type is "builtins.int"
mypy_example.py:16: note: Revealed type is "jobflow.core.job.Job"
mypy_example.py:17: note: Revealed type is "jobflow.core.job.Job"

Which is the intended behaviour in my opinion.

@utf
Copy link
Member

utf commented Apr 3, 2024

This is really nice. Thank you.

@utf utf merged commit f27d2de into materialsproject:main Apr 3, 2024
7 checks passed
@utf utf added the enhancement New feature or request label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants