summaryrefslogtreecommitdiffstats
path: root/lib/ansible/module_utils/compat/typing.py
blob: 27b25f7738b62c742db5c44478f65c93a3071042 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
"""Compatibility layer for the `typing` module, providing all Python versions access to the newest type-hinting features."""
from __future__ import (absolute_import, division, print_function)
__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 Exception:  # pylint: disable=broad-except
    pass

try:
    from typing import *  # type: ignore[misc]
except Exception:  # pylint: disable=broad-except
    pass


try:
    cast
except NameError:
    def cast(typ, val):  # type: ignore[no-redef]
        return val