kr8s-org / kr8s

A batteries-included Python client library for Kubernetes that feels familiar for folks who already know how to use kubectl
https://kr8s.org
BSD 3-Clause "New" or "Revised" License
839 stars 45 forks source link

Strict `mypy` typing #428

Open jacobtomlinson opened 4 months ago

jacobtomlinson commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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.