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
script_defs: Remove None assertion #1244
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.
I was going to write some feedback about being more explicit, like adding types to r
and d
, but mypy is smart enough already!
[nix-shell:~/projects/github.com/NixOS/nixops]$ git diff
diff --git a/nixops/script_defs.py b/nixops/script_defs.py
index b0c283a..adb5e81 100644
--- a/nixops/script_defs.py
+++ b/nixops/script_defs.py
@@ -234,8 +234,8 @@ def op_info(args):
)
for name in names:
- d = definitions.get(name)
- r = depl.resources.get(name)
+ d: str = definitions.get(name)
+ r: str = depl.resources.get(name)
assert r is not None
if deployment.is_machine(r):
resource_state = "{0} / {1}".format(
[nix-shell:~/projects/github.com/NixOS/nixops]$ mypy nixops
nixops/script_defs.py:237: error: Incompatible types in assignment (expression has type "Optional[ResourceDefinition]", variable has type "str")
nixops/script_defs.py:238: error: Incompatible types in assignment (expression has type "Optional[ResourceState]", variable has type "str")
I was looking at the mypy html report, and if you'd like to help "clean up the campground" a bit, there is a trivial additional thing you could do:
adding -> str
to resources/init.py's show_type()
and also adding types to def state(depl, d, m):
in script_defs.py
.
`r` being `None` is peferctly valid when the resource does not yet exist. Without this fix a resource not yet deployed fails with AssertionError.
dc6ba23
to
c905ca8
Compare
@grahamc Updated PR with more typing. |
ce8daeb
to
2b7cc8a
Compare
resources: 45.58% imprecise ->41.50% imprecise |
r
beingNone
is peferctly valid when the resource does not yet exist.Without this fix a resource not yet deployed fails with AssertionError.