summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2022-08-03 12:30:23 -0500
committerGitHub <noreply@github.com>2022-08-03 10:30:23 -0700
commitf6fcb5669518de6bfdfd5358d79b08e225c37158 (patch)
treec44935ec80f24674a4e84f9720a02e86d7716213
parentff4bb5500a79609de7d23253b2f25713eeaf6bfe (diff)
downloadansible-f6fcb5669518de6bfdfd5358d79b08e225c37158.tar.gz
[stable-2.13] swallow all exceptions in type annotation support shim imports (#77860) (#78373)
* swallow all exceptions in type annotation support shim imports * add changelog (cherry picked from commit 813afcb) Co-authored-by: Matt Davis <6775756+nitzmahone@users.noreply.github.com> Co-authored-by: Matt Davis <6775756+nitzmahone@users.noreply.github.com>
-rw-r--r--changelogs/fragments/type_shim_exception_swallow.yml2
-rw-r--r--lib/ansible/module_utils/compat/typing.py7
2 files changed, 7 insertions, 2 deletions
diff --git a/changelogs/fragments/type_shim_exception_swallow.yml b/changelogs/fragments/type_shim_exception_swallow.yml
new file mode 100644
index 0000000000..394f406b27
--- /dev/null
+++ b/changelogs/fragments/type_shim_exception_swallow.yml
@@ -0,0 +1,2 @@
+bugfixes:
+- prevent type annotation shim failures from causing runtime failures (https://github.com/ansible/ansible/pull/77860)
diff --git a/lib/ansible/module_utils/compat/typing.py b/lib/ansible/module_utils/compat/typing.py
index cd644b1c3b..c361a86717 100644
--- a/lib/ansible/module_utils/compat/typing.py
+++ b/lib/ansible/module_utils/compat/typing.py
@@ -4,12 +4,15 @@ __metaclass__ = type
# pylint: disable=wildcard-import,unused-wildcard-import
+# catch *all* exceptions to prevent type annotation support module bugs causing runtime failures
+# (eg, https://github.com/ansible/ansible/issues/77857)
+
try:
from typing_extensions import *
-except ImportError:
+except Exception: # pylint: disable=broad-except
pass
try:
from typing import * # type: ignore[misc]
-except ImportError:
+except Exception: # pylint: disable=broad-except
pass