From f6fcb5669518de6bfdfd5358d79b08e225c37158 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Wed, 3 Aug 2022 12:30:23 -0500 Subject: [PATCH] [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> --- changelogs/fragments/type_shim_exception_swallow.yml | 2 ++ lib/ansible/module_utils/compat/typing.py | 7 +++++-- 2 files changed, 7 insertions(+), 2 deletions(-) create mode 100644 changelogs/fragments/type_shim_exception_swallow.yml diff --git a/changelogs/fragments/type_shim_exception_swallow.yml b/changelogs/fragments/type_shim_exception_swallow.yml new file mode 100644 index 00000000000..394f406b276 --- /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 cd644b1c3bc..c361a867176 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