| 1 |
import sys |
| 2 |
from typing import Literal |
| 3 |
|
| 4 |
if sys.version_info >= (3, 14): |
| 5 |
import enum |
| 6 |
import types |
| 7 |
from _typeshed import AnnotateFunc, AnnotationForm, EvaluateFunc, SupportsItems |
| 8 |
from collections.abc import Mapping |
| 9 |
from typing import Any, ParamSpec, TypeVar, TypeVarTuple, final, overload |
| 10 |
from warnings import deprecated |
| 11 |
|
| 12 |
__all__ = [ |
| 13 |
"Format", |
| 14 |
"ForwardRef", |
| 15 |
"call_annotate_function", |
| 16 |
"call_evaluate_function", |
| 17 |
"get_annotate_from_class_namespace", |
| 18 |
"get_annotations", |
| 19 |
"annotations_to_string", |
| 20 |
"type_repr", |
| 21 |
] |
| 22 |
|
| 23 |
class Format(enum.IntEnum): |
| 24 |
VALUE = 1 |
| 25 |
VALUE_WITH_FAKE_GLOBALS = 2 |
| 26 |
FORWARDREF = 3 |
| 27 |
STRING = 4 |
| 28 |
|
| 29 |
@final |
| 30 |
class ForwardRef: |
| 31 |
__slots__ = ( |
| 32 |
"__forward_is_argument__", |
| 33 |
"__forward_is_class__", |
| 34 |
"__forward_module__", |
| 35 |
"__weakref__", |
| 36 |
"__arg__", |
| 37 |
"__globals__", |
| 38 |
"__extra_names__", |
| 39 |
"__code__", |
| 40 |
"__ast_node__", |
| 41 |
"__cell__", |
| 42 |
"__owner__", |
| 43 |
"__stringifier_dict__", |
| 44 |
) |
| 45 |
__forward_is_argument__: bool |
| 46 |
__forward_is_class__: bool |
| 47 |
__forward_module__: str | None |
| 48 |
def __init__( |
| 49 |
self, arg: str, *, module: str | None = None, owner: object = None, is_argument: bool = True, is_class: bool = False |
| 50 |
) -> None: ... |
| 51 |
@overload |
| 52 |
def evaluate( |
| 53 |
self, |
| 54 |
*, |
| 55 |
globals: dict[str, Any] | None = None, |
| 56 |
locals: Mapping[str, Any] | None = None, |
| 57 |
type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] | None = None, |
| 58 |
owner: object = None, |
| 59 |
format: Literal[Format.STRING], |
| 60 |
) -> str: ... |
| 61 |
@overload |
| 62 |
def evaluate( |
| 63 |
self, |
| 64 |
*, |
| 65 |
globals: dict[str, Any] | None = None, |
| 66 |
locals: Mapping[str, Any] | None = None, |
| 67 |
type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] | None = None, |
| 68 |
owner: object = None, |
| 69 |
format: Literal[Format.FORWARDREF], |
| 70 |
) -> AnnotationForm | ForwardRef: ... |
| 71 |
@overload |
| 72 |
def evaluate( |
| 73 |
self, |
| 74 |
*, |
| 75 |
globals: dict[str, Any] | None = None, |
| 76 |
locals: Mapping[str, Any] | None = None, |
| 77 |
type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] | None = None, |
| 78 |
owner: object = None, |
| 79 |
format: Format = Format.VALUE, |
| 80 |
) -> AnnotationForm: ... |
| 81 |
@deprecated("Use `ForwardRef.evaluate()` or `typing.evaluate_forward_ref()` instead.") |
| 82 |
def _evaluate( |
| 83 |
self, |
| 84 |
globalns: dict[str, Any] | None, |
| 85 |
localns: Mapping[str, Any] | None, |
| 86 |
type_params: tuple[TypeVar | ParamSpec | TypeVarTuple, ...] = ..., |
| 87 |
*, |
| 88 |
recursive_guard: frozenset[str], |
| 89 |
) -> AnnotationForm: ... |
| 90 |
@property |
| 91 |
def __forward_arg__(self) -> str: ... |
| 92 |
@property |
| 93 |
def __forward_code__(self) -> types.CodeType: ... |
| 94 |
def __eq__(self, other: object) -> bool: ... |
| 95 |
def __hash__(self) -> int: ... |
| 96 |
def __or__(self, other: Any) -> types.UnionType: ... |
| 97 |
def __ror__(self, other: Any) -> types.UnionType: ... |
| 98 |
|
| 99 |
@overload |
| 100 |
def call_evaluate_function(evaluate: EvaluateFunc, format: Literal[Format.STRING], *, owner: object = None) -> str: ... |
| 101 |
@overload |
| 102 |
def call_evaluate_function( |
| 103 |
evaluate: EvaluateFunc, format: Literal[Format.FORWARDREF], *, owner: object = None |
| 104 |
) -> AnnotationForm | ForwardRef: ... |
| 105 |
@overload |
| 106 |
def call_evaluate_function(evaluate: EvaluateFunc, format: Format, *, owner: object = None) -> AnnotationForm: ... |
| 107 |
@overload |
| 108 |
def call_annotate_function( |
| 109 |
annotate: AnnotateFunc, format: Literal[Format.STRING], *, owner: object = None |
| 110 |
) -> dict[str, str]: ... |
| 111 |
@overload |
| 112 |
def call_annotate_function( |
| 113 |
annotate: AnnotateFunc, format: Literal[Format.FORWARDREF], *, owner: object = None |
| 114 |
) -> dict[str, AnnotationForm | ForwardRef]: ... |
| 115 |
@overload |
| 116 |
def call_annotate_function(annotate: AnnotateFunc, format: Format, *, owner: object = None) -> dict[str, AnnotationForm]: ... |
| 117 |
def get_annotate_from_class_namespace(obj: Mapping[str, object]) -> AnnotateFunc | None: ... |
| 118 |
@overload |
| 119 |
def get_annotations( |
| 120 |
obj: Any, |
| 121 |
*, |
| 122 |
globals: dict[str, object] | None = None, |
| 123 |
locals: Mapping[str, object] | None = None, |
| 124 |
eval_str: bool = False, |
| 125 |
format: Literal[Format.STRING], |
| 126 |
) -> dict[str, str]: ... |
| 127 |
@overload |
| 128 |
def get_annotations( |
| 129 |
obj: Any, |
| 130 |
*, |
| 131 |
globals: dict[str, object] | None = None, |
| 132 |
locals: Mapping[str, object] | None = None, |
| 133 |
eval_str: bool = False, |
| 134 |
format: Literal[Format.FORWARDREF], |
| 135 |
) -> dict[str, AnnotationForm | ForwardRef]: ... |
| 136 |
@overload |
| 137 |
def get_annotations( |
| 138 |
obj: Any, |
| 139 |
*, |
| 140 |
globals: dict[str, object] | None = None, |
| 141 |
locals: Mapping[str, object] | None = None, |
| 142 |
eval_str: bool = False, |
| 143 |
format: Format = Format.VALUE, |
| 144 |
) -> dict[str, AnnotationForm]: ... |
| 145 |
def type_repr(value: object) -> str: ... |
| 146 |
def annotations_to_string(annotations: SupportsItems[str, object]) -> dict[str, str]: ... |