-
-
Notifications
You must be signed in to change notification settings - Fork 149
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
Introduce typehints in controller #881
Introduce typehints in controller #881
Conversation
@jacobtomlinson I converged to a somewhat rounded midpoint now; there still are a handful of Let me know what you think about my PR in general; it is unfortunately quite large, but I did it to improve developer experience (I honestly found contributing to this repository a bit hard since it is almost impossible to know which types are used where). I would prefer not increasing the scope of this PR even further for now but to do only clean up. Also, I did not include Maybe I can find some time to also add type hints to other parts of this repo in the distant future. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking the time here.
Generally our policy in Dask projects is to do type hinting on a best efforts basis. It is by no means mandatory and I don't think we ever want to enforce it here as it will likely obstruct novice contributors.
I'm more than happy to accept PRs like this that improve hinting provided the code becomes more readable and continues to function the same. If you want to invest more time on this in the future that would be great too, but accepting this PR isn't conditional on you following it through to mypy
being 100% happy.
Unfortunately the CI is failing so I'm guessing these changes have broken something. Would you be able to investigate the errors and fix things up?
@@ -410,18 +472,18 @@ async def retire_workers( | |||
) | |||
# Dask version mismatches between the operator and scheduler may cause this to fail in any number of unexpected ways | |||
with suppress(Exception): | |||
comm_address = await get_scheduler_address( | |||
comm_address = await get_scheduler_address( # type: ignore[no-untyped-call] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are a lot of these ignore throughout. Perhaps it makes sense to ignore this globally via the project config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm personally more on the "the more explicit and correct, the better"-side (because ignoring it globally could potentially mask bugs, depending on which error you want to ignore) but I'm happy to use the way that works for everybody. Note that these untyped calls would actually vanish as soon as the entire repo would be properly typed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the thing I would say here is that Dask strives to be a project that is welcoming to novice developers. My concern with type hinting in general is it can be very daunting for junior developers, even if it helps them avoid shooting their foot off.
Removing inline ignores I feel is a good way to remove some visual clutter that may be daunting for some folks. So even though it may mask a bug here and there I would prefer a global ignore.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, if you'd prefer a global ignore for no-untyped-call
& import-untyped
, we can integrate this into the pyproject.toml
. I'll do it when I find time for it.
|
||
import dask.config | ||
import pytest | ||
import yaml | ||
from dask.distributed import Client | ||
from kr8s.asyncio.objects import Deployment, Pod, Service | ||
from kr8s.asyncio.objects import Deployment, Pod, Service # type: ignore[import-untyped] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with this ignore, should we disable this for the whole project?
@jacobtomlinson could you help me out with this piece of code here: In the top-level This class actually is very much different from the Why is there a differentation, why is the default pointing to the "classic" The CI errors actually stemmed from me trying to importing |
141c291
to
9855fd4
Compare
@jonded94 it was done this way when we deprecated the classic In the past users would do Enough time has passed now that we can do away with all of this. The classic codebase can be totally removed. Then we need to make a decision about should we allow |
Okay, so the idea would be to include a DeprecationWarning in the future then as soon somebody is importing that classic thing, got it (because right now it simply imports it with no further warning or output). This is something separate then from this PR :) Thanks for your clarification! |
Yeah, it was actually there previously, but we moved it again because there were some usage patterns that meant it didn't show up.
I basically consider the classic code overdue for removal. I just haven't had the time lately to do the work. Hoping to get to it very soon. |
I took the plunge and removed the classic codebase in #890. Would you mind rebasing this PR? |
…ository. Make sure exported symbols are correctly set in __init__.py with __all__. Renamed pytest fixture for creating a k8s namespace from ns to namespace since ns is a bit overloaded, especially in test_controller.py Introduce typehints in controller.py and test_controller.py to massively improve developer experience (previously, one just really had to guess what functions are for and which types are expected) Removed unused function parameters Made function headers (i.e. parameter [type] defintion) compatible with what `kopf.on.[create/change/...]' expects Introduce mypy (and missing stubs of external packages if available) Introduce mypy ignores for (still) untyped parts of the codebase for now
9855fd4
to
82c1d93
Compare
Very nice to hear! :) Rebased my PR. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I've given it another pass and have a few more comments.
@@ -410,18 +472,18 @@ async def retire_workers( | |||
) | |||
# Dask version mismatches between the operator and scheduler may cause this to fail in any number of unexpected ways | |||
with suppress(Exception): | |||
comm_address = await get_scheduler_address( | |||
comm_address = await get_scheduler_address( # type: ignore[no-untyped-call] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the thing I would say here is that Dask strives to be a project that is welcoming to novice developers. My concern with type hinting in general is it can be very daunting for junior developers, even if it helps them avoid shooting their foot off.
Removing inline ignores I feel is a good way to remove some visual clutter that may be daunting for some folks. So even though it may mask a bug here and there I would prefer a global ignore.
…untyped external calls
I now fixed the remarks, i.e.:
After merging this MR, the next step surely would be to introduce |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great to me.
Very happy to add mypy
to the pre-commit
checks just for the controller for now. Let's do that in a follow up PR.
General code quality improvements for the controller part of this repository.
__init__.py
with__all__
.ns
tonamespace
sincens
is a bit overloaded, especially intest_controller.py
controller.py
andtest_controller.py
to massively improve developer experience (previously, one just really had to guess what functions are for and which types are expected)