File: _compat.py

package info (click to toggle)
python-pdoc 16.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,080 kB
  • sloc: python: 5,260; javascript: 1,156; makefile: 18; sh: 3
file content (35 lines) | stat: -rw-r--r-- 833 bytes parent folder | download
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
26
27
28
29
30
31
32
33
34
35
# fmt: off
import sys

if sys.version_info >= (3, 12):
    from ast import TypeAlias as ast_TypeAlias
else:  # pragma: no cover
    class ast_TypeAlias:
        pass

if sys.version_info >= (3, 12):
    from typing import TypeAliasType
else:  # pragma: no cover
    class TypeAliasType:
        """Placeholder class for TypeAliasType"""

if (3, 10) <= sys.version_info < (3, 10, 1):  # pragma: no cover
    import inspect
    import types

    def formatannotation(annotation) -> str:
        """
        https://github.com/python/cpython/pull/29212
        """
        if isinstance(annotation, types.GenericAlias):
            return str(annotation)
        return inspect.formatannotation(annotation)
else:
    from inspect import formatannotation


__all__ = [
    "ast_TypeAlias",
    "TypeAliasType",
    "formatannotation",
]