Add NoReturn annotations in module_utils (#84106)

pull/83337/head
Matt Clay 1 year ago committed by GitHub
parent 56bab1d097
commit b3950bc864
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,2 @@
minor_changes:
- module_utils - Add ``NoReturn`` type annotations to functions which never return.

@ -6,6 +6,7 @@ from __future__ import annotations
import json
import sys
import typing as t
# Used for determining if the system is running a new enough python version
# and should only restrict on our documented minimum versions
@ -1446,14 +1447,14 @@ class AnsibleModule(object):
print('\n%s' % self.jsonify(kwargs))
def exit_json(self, **kwargs):
def exit_json(self, **kwargs) -> t.NoReturn:
""" return from the module, without error """
self.do_cleanup_files()
self._return_formatted(kwargs)
sys.exit(0)
def fail_json(self, msg, **kwargs):
def fail_json(self, msg, **kwargs) -> t.NoReturn:
""" return from the module, with an error message """
kwargs['failed'] = True

@ -6,6 +6,7 @@ from __future__ import annotations
import os
import subprocess
import sys
import typing as t
from ansible.module_utils.common.text.converters import to_bytes
@ -14,7 +15,7 @@ def has_respawned():
return hasattr(sys.modules['__main__'], '_respawned')
def respawn_module(interpreter_path):
def respawn_module(interpreter_path) -> t.NoReturn:
"""
Respawn the currently-running Ansible Python module under the specified Python interpreter.

Loading…
Cancel
Save