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

Strict mypy typing #428

Open
jacobtomlinson opened this issue Jul 2, 2024 · 3 comments
Open

Strict mypy typing #428

jacobtomlinson opened this issue Jul 2, 2024 · 3 comments
Labels
enhancement New feature or request typing

Comments

@jacobtomlinson
Copy link
Member

Which project are you requesting an enhancement for?

kr8s

What do you need?

Continuing on from #381 it might be fun to get mypy --strict passing. This is by no means necessary but it might make kr8s even more pleasant to use for folks who like strong type annotations and help shake out some bugs.

It's unclear whether --strict should be added to the precommit hooks as strict typing may increase the barrier to contributing too much.

@max-muoto
Copy link
Contributor

max-muoto commented Jul 7, 2024

Have you looked into Pyright? I think there are a lot of reasons to consider it over MyPy for open-source libraries hoping to enforce strict typing. It's by far the most compliant with the Python typing spec, and already has support for 3.12-3.13 features through typing extensions.

@jacobtomlinson
Copy link
Member Author

I hadn't considrered it, I'm not especially familiar with Pyright. Given that it checks all untyped code by default it does make sense to equate it to mypy --strict.

I see most projects that I contribute to using mypy, but maybe that's changing? I'm generally happy to use whatever tools makes kr8s the best for the community, so if folks want pyright here then I encourage 👍 reactions on your comment 😃.

@max-muoto
Copy link
Contributor

I hadn't considrered it, I'm not especially familiar with Pyright. Given that it checks all untyped code by default it does make sense to equate it to mypy --strict.

I see most projects that I contribute to using mypy, but maybe that's changing? I'm generally happy to use whatever tools makes kr8s the best for the community, so if folks want pyright here then I encourage 👍 reactions on your comment 😃.

I'd say in most cases it's going to be stricter, one difference is that Pyright technically doesn't require you annotate all return paths. While it's probably a good idea for MyPy users (you can enforce this through Ruff's ANN rule-set instead), it has similar inference capabilities to TypeScript. This can especially be helpful with untyped/partially typed libraries you're bringing in though. MyPy just assumes Any in the case that a return-type is provided, which can obviously lead to more typing issues if you're dealing with some external code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request typing
Projects
None yet
Development

No branches or pull requests

2 participants