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