-
Notifications
You must be signed in to change notification settings - Fork 518
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
[Mypy] Add more mypy #1564
[Mypy] Add more mypy #1564
Conversation
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 @Michaelvll! I've reviewed 16/36 files (up to execution.py
). I can do more reviews late next week, but I would like someone else to look at this if they can get to it before 19th Jan.
format.sh
Outdated
@@ -98,8 +98,6 @@ mypy $(cat tests/mypy_files.txt) | |||
# Run Pylint | |||
echo 'Sky Pylint:' | |||
pylint --load-plugins pylint_quotes sky |
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.
on running format.sh, I got an error:
(base) romilb@romilbx1yoga:/mnt/d/Romil/Berkeley/Research/sky-experiments$ ./format.sh
SkyPilot mypy:
sky/authentication.py:187: error: No overload variant of "get" of "dict" matches argument types "str", "str" [call-overload]
sky/authentication.py:187: note: Possible overload variants:
sky/authentication.py:187: note: def get(self, <nothing>, /) -> None
sky/authentication.py:187: note: def [_T] get(self, <nothing>, _T, /) -> _T
sky/authentication.py:249: error: No overload variant of "get" of "dict" matches argument types "str", "str" [call-overload]
sky/authentication.py:249: note: Possible overload variants:
sky/authentication.py:249: note: def get(self, <nothing>, /) -> None
sky/authentication.py:249: note: def [_T] get(self, <nothing>, _T, /) -> _T
Found 2 errors in 1 file (checked 83 source files)
Here's my pip freeze if it helps
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.
Hmm, that is weird. Could you share the python version you are using?
@@ -2102,7 +2101,7 @@ def _provision(self, | |||
raise exceptions.ResourcesUnavailableError( | |||
error_message) from None | |||
if dryrun: | |||
return | |||
return None |
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.
Should we change other instances of return
to return None
to be consistent? (as suggested in pep8 - "Be consistent in return statements"). E.g. at L2277
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 added the return None for the LocalDockerBackend._provision
as well, but for the return statement at L2277, the method has a return type annotation as -> None
, so it seems to be fine (or more intuitive) to not having the return value in the return statement.
Seems the standard for being consistent for the return statement has a scope of each function, IIUC. It might be fine to only have the return statement consistent in a single function.
Either all return statements in a function should return an expression, or none of them should.
With the latest changes, I avoid the nested class of the |
A kind reminder for this PR @romilbhardwaj. : ) |
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 @Michaelvll! Sorry about the delay in getting to this. Left some comments, particularly need some more on clarity on why pyi stub files are needed. Rest looks great!
@@ -0,0 +1,108 @@ | |||
from sky import sky_logging as sky_logging |
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 a little new to mypy, but is this stub file necessary if we fully type log_lib.py
?
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 stub file is mainly for the type hint of run_with_log
where we want to determine the return type by the value of the argument require_outputs
. To remove this stub file, we can move the two typing.overload
back into the original log_lib.py
, but that may make that file much longer. Wdyt?
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.
Ahh... I think it would be nicer to move the overload definitions to log_lib.py
(fewer files to deal with, easier to maintain).
On a related note - should we reconsider why we have different return types for run_with_log
? It would be nice if we can get away with Tuple[int, str, str]
and return proc.returncode, '', ''
when require_outputs is false? Feel free to defer for later too
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.
(Casual skim, didn't read the discussion in full) .pyi
files being standalone seems common practice:
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.
Oops, sorry. Just realized, another reason we have to use the stub file is that the pylint has a bug with the type overload in the same file (reference). It will not correctly recognize the overloaded types and complain about sky/backends/cloud_vm_ray_backend.py:1362:8: E0633: Attempting to unpack a non-sequence (unpacking-non-sequence)
.
I tried to upgrade the pylint to the latest version but the problem still exists. I had to keep the stub file for now.
I am planning to refactor the require_outputs
and remove the stub file in another PR as otherwise, the changes will be mixed with the mypy changes in this PR, making it hard to distinguish the changes. : )
bf79d5c
to
7242b64
Compare
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 adding this @Michaelvll! This will help us catch bugs a lot faster : ) Should be good to merge if all tests pass.
sky/backends/backend_utils.py
Outdated
SKY_RESERVED_CLUSTER_NAMES = { | ||
spot_lib.SPOT_CONTROLLER_NAME: 'Managed spot controller' | ||
SKY_RESERVED_CLUSTER_NAMES: Dict[str, str] = { | ||
spot_lib.SPOT_CONTROLLER_NAME: 'Managed spot controller' # type: 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.
This # type: ignore
seems not required - mypy passes without this too
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.
Oops, good catch! Removed it. Thanks!
Thanks for the review @romilbhardwaj! Tested:
|
* backend_utils mypy * More mypy * format * order * change to exclude * remove unused registry.py * add back task.py * dependency * quote * fix circular import * fix * remove unused * fix issue with master * refactor ResourceHandle * fix * dryrun for local docker backend * lint * fix merge issue * Address comments * lint * format * remote type ignore * add typing extensions to the dependency
This PR adds mypy checks for almost all the modules excluding the following files:
Except for the modules with comments above, we will add mypy checks for the rest of the files in a future PR.
Tested (run the relevant ones):
bash tests/run_smoke_tests.sh
bash tests/backward_comaptibility_tests.sh