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

script_defs: Remove None assertion #1244

Merged
merged 5 commits into from Mar 10, 2020
Merged

Conversation

@adisbladis
Copy link
Member

adisbladis commented Mar 6, 2020

r being None is peferctly valid when the resource does not yet exist.

Without this fix a resource not yet deployed fails with AssertionError.

@grahamc
grahamc approved these changes Mar 6, 2020
Copy link
Member

grahamc left a comment

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:

image

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.
@adisbladis adisbladis force-pushed the adisbladis:assert-none-script-defs branch from dc6ba23 to c905ca8 Mar 9, 2020
@adisbladis

This comment has been minimized.

Copy link
Member Author

adisbladis commented Mar 9, 2020

@grahamc Updated PR with more typing.

nixops/script_defs.py Outdated Show resolved Hide resolved
grahamc added 3 commits Mar 9, 2020
@adisbladis adisbladis force-pushed the adisbladis:assert-none-script-defs branch from ce8daeb to 2b7cc8a Mar 10, 2020
@grahamc

This comment has been minimized.

Copy link
Member

grahamc commented Mar 10, 2020

resources: 45.58% imprecise ->41.50% imprecise
script_defs: 58.85% imprecise -> 57.95% imprecise

@grahamc grahamc merged commit b4c38df into NixOS:master Mar 10, 2020
1 check passed
1 check passed
Travis CI - Pull Request Build Passed
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.