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

In 3.5.2, code using luigi fails mypy type checks #3312

Open
ccmaymay opened this issue Sep 5, 2024 · 0 comments
Open

In 3.5.2, code using luigi fails mypy type checks #3312

ccmaymay opened this issue Sep 5, 2024 · 0 comments

Comments

@ccmaymay
Copy link
Contributor

ccmaymay commented Sep 5, 2024

The mypy type checker accepted the following code before 3.5.2:

import luigi  # type: ignore


def process_string(s: str) -> str:
    return s


class Streams(luigi.Task):
    param = luigi.Parameter()

    def run(self) -> None:
        with self.output().open('w') as output:
            output.write(process_string(self.param))

    def output(self) -> luigi.LocalTarget:
        return luigi.LocalTarget('data.txt')

But with the addition of py.typed in 3.5.2, mypy complains:

mwe.py:13: error: Argument 1 to "process_string" has incompatible type "Parameter"; expected "str"  [arg-type]
Found 1 error in 1 file (checked 1 source file)

At runtime in the user code, the param member isn't an instance of Parameter; rather, it has been overwritten here with the parsed, normalized parameter value, which has the expected type.

Is there any guidance on writing type-checked code in 3.5.2? Or will type compliance be added later? Otherwise, could the addition of py.typed be reverted?

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant