-
-
Notifications
You must be signed in to change notification settings - Fork 363
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
2-to-3: Start with types #1232
2-to-3: Start with types #1232
Conversation
This test assumes peculiar ordering guarantees which have changed from python2. This switches it to be the output from python3, but a proper fix would either to test equality only up to permutation, or to fix and guarantee an actual ordering.
def _definition_for_required( | ||
self, name: str | ||
) -> nixops.resources.ResourceDefinition: | ||
defn = self._definition_for(name) | ||
if defn is None: | ||
raise Exception("Bug: Deployment.definitions['{}'] is None.".format(name)) | ||
return defn | ||
|
||
def _machine_definition_for_required( | ||
self, name: str | ||
) -> nixops.backends.MachineDefinition: | ||
defn = self._definition_for_required(name) | ||
if not isinstance(defn, nixops.backends.MachineDefinition): | ||
raise Exception("Definition named '{}' is not a machine.".format(name)) | ||
return defn |
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.
Under the old behavior:
- self.definitions was None, causing
self.definititions[name]
to be an Exception -- no change - self.definitions was a Dict, causing
self.definititions[name]
to be possibly None -- generally not causing an Exception, but instead propogating a None around - self.definitions was a Dict,
self.definititions[name]
was something, but not a Machine -- instead a different kind of resource. I believe this would cause an exception.
In other words, the only case I'm somewhat unsure about is the None case.
Also: there are commits from the other PR that I'm going to bring over here. |
…s renamed to json
This reverts commit 766e5e8.
Now improved to:
In particular, known_hosts 51.39% -> 11.43%, state 60% -> 22%! |
I found no issues with my usual workflow on this branch, using the |
I didn't run into any issues when running without plugins, trying out the following commands: |
An alternative implementation of #1238 from GitHub user doshitan which used Literal[...] as a sort of dependent type: + @overload + def run_command( + self, + command: Command, + flags: List[str] = ..., + timeout: Optional[int] = ..., + logged: bool = ..., + allow_ssh_args: bool = ..., + user: Optional[str] = ..., + *, + capture_stdout: Literal[False], + **kwargs: Any + ) -> int: + ... + + @overload + def run_command( + self, + command: Command, + flags: List[str] = ..., + timeout: Optional[int] = ..., + logged: bool = ..., + allow_ssh_args: bool = ..., + user: Optional[str] = ..., + *, + capture_stdout: Literal[True], + **kwargs: Any + ) -> str: + ... + + @overload + def run_command( + self, + command: Command, + flags: List[str] = [], + timeout: Optional[int] = None, + logged: bool = True, + allow_ssh_args: bool = False, + user: Optional[str] = None, + **kwargs: Any + ) -> Union[str, int]: + ... however, I think this option is much simpler and improves the API. Possibly in the future we will add this more complex type.
💕 💕 🌈 |
A rethinking of #1227 which starts by adding types where there are problems. Adds types and corrects issues where
mypy
was unhappy, after asking it to check untyped defs.(Don't merge.)