Skip to content

Commit

Permalink
Add type hints to ansible.utils.display::Display (ansible#81400)
Browse files Browse the repository at this point in the history
* Add type hints to ansible.utils.display::Display

Fixes ansible#80841

* Avoid circular import

* Fix sanity

* type hint some of the functions of the module?

* Fix units

* Not sure about this

* Fix some of the issues from reviews

* Add changelog

* ...

* Update lib/ansible/utils/display.py

Co-authored-by: Sviatoslav Sydorenko <[email protected]>

* remove py2 boilerplate

---------

Co-authored-by: Sviatoslav Sydorenko <[email protected]>
  • Loading branch information
mkrizek and webknjaz authored Sep 5, 2023
1 parent 48d8e06 commit 4d40988
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 59 deletions.
4 changes: 4 additions & 0 deletions changelogs/fragments/80841-display-type-annotation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
minor_changes:
- Add Python type hints to the Display class (https://github.com/ansible/ansible/issues/80841)
bugfixes:
- vars_prompt - internally convert the ``unsafe`` value to ``bool``
2 changes: 1 addition & 1 deletion lib/ansible/executor/playbook_executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def run(self):
encrypt = var.get("encrypt", None)
salt_size = var.get("salt_size", None)
salt = var.get("salt", None)
unsafe = var.get("unsafe", None)
unsafe = boolean(var.get("unsafe", False))

if vname not in self._variable_manager.extra_vars:
if self._tqm:
Expand Down
4 changes: 2 additions & 2 deletions lib/ansible/playbook/play_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ class PlayContext(Base):
def verbosity(self):
display.deprecated(
"PlayContext.verbosity is deprecated, use ansible.utils.display.Display.verbosity instead.",
version=2.18
version="2.18"
)
return self._internal_verbosity

@verbosity.setter
def verbosity(self, value):
display.deprecated(
"PlayContext.verbosity is deprecated, use ansible.utils.display.Display.verbosity instead.",
version=2.18
version="2.18"
)
self._internal_verbosity = value

Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/plugins/connection/ssh.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def wrapped(self: Connection, *args: P.args, **kwargs: P.kwargs) -> tuple[int, b
if self._play_context.no_log:
display.vvv(u'rc=%s, stdout and stderr censored due to no log' % return_tuple[0], host=self.host)
else:
display.vvv(return_tuple, host=self.host)
display.vvv(str(return_tuple), host=self.host)
# 0 = success
# 1-254 = remote command return code
# 255 could be a failure from the ssh command itself
Expand Down
Loading

0 comments on commit 4d40988

Please sign in to comment.