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

fix @job annotation again (again) #654

Merged
merged 1 commit into from
Jul 30, 2024

Conversation

FabiPi3
Copy link
Contributor

@FabiPi3 FabiPi3 commented Jul 25, 2024

Serves as a follow-up for #578 . I recognized that there is another use case, which is for example used in here: https://github.com/materialsproject/atomate2/blob/e210b58b93d33b13af800dd001c9689f96a6eb0c/src/atomate2/vasp/jobs/base.py#L150

This requires another overload block. Here is the quick example extended:

from jobflow import job

def add(a: int, b: int) -> int:
    """Add function."""
    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}

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

def job_wrapper(method: Callable[..., Any]) -> Callable[..., Job]:
    """Job wrapper."""
    return job(method, data="data")

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


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

Running mypy over this using old master branch:

error: No overload variant of "job" matches argument types "None", "str", "str"  [call-overload]
error: Incompatible return value type (got "Callable[..., Callable[..., Job]]", expected "Callable[..., Job]")  [return-value]
Revealed type is "builtins.int"
Revealed type is "jobflow.core.job.Job"
Revealed type is "jobflow.core.job.Job"
Revealed type is "Any"
Revealed type is "jobflow.core.job.Job"

And now with the new version:

Revealed type is "builtins.int"
Revealed type is "jobflow.core.job.Job"
Revealed type is "jobflow.core.job.Job"
Revealed type is "jobflow.core.job.Job"
Revealed type is "jobflow.core.job.Job"

@utf
Copy link
Member

utf commented Jul 30, 2024

Thanks!

@utf utf merged commit a740c6c into materialsproject:main Jul 30, 2024
7 checks passed
@utf utf added the fix Bug fix label Nov 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants