summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util/typing.py
blob: 62a9f6c8a8dc8f642959faa623a56590ba3d1812 (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import typing
from typing import Any
from typing import Callable  # noqa
from typing import Generic
from typing import overload
from typing import Type
from typing import TypeVar
from typing import Union

from typing_extensions import NotRequired  # noqa

from . import compat

_T = TypeVar("_T", bound=Any)

if typing.TYPE_CHECKING or not compat.py38:
    from typing_extensions import Literal  # noqa F401
    from typing_extensions import Protocol  # noqa F401
    from typing_extensions import TypedDict  # noqa F401
else:
    from typing import Literal  # noqa F401
    from typing import Protocol  # noqa F401
    from typing import TypedDict  # noqa F401

if typing.TYPE_CHECKING or not compat.py310:
    from typing_extensions import Concatenate  # noqa F401
    from typing_extensions import ParamSpec  # noqa F401
else:
    from typing import Concatenate  # noqa F401
    from typing import ParamSpec  # noqa F401


class _TypeToInstance(Generic[_T]):
    """describe a variable that moves between a class and an instance of
    that class.

    """

    @overload
    def __get__(self, instance: None, owner: Any) -> Type[_T]:
        ...

    @overload
    def __get__(self, instance: object, owner: Any) -> _T:
        ...

    def __get__(self, instance: object, owner: Any) -> Union[Type[_T], _T]:
        ...

    @overload
    def __set__(self, instance: None, value: Type[_T]) -> None:
        ...

    @overload
    def __set__(self, instance: object, value: _T) -> None:
        ...

    def __set__(self, instance: object, value: Union[Type[_T], _T]) -> None:
        ...


class ReadOnlyInstanceDescriptor(Protocol[_T]):
    """protocol representing an instance-only descriptor"""

    @overload
    def __get__(
        self, instance: None, owner: Any
    ) -> "ReadOnlyInstanceDescriptor[_T]":
        ...

    @overload
    def __get__(self, instance: object, owner: Any) -> _T:
        ...

    def __get__(
        self, instance: object, owner: Any
    ) -> Union["ReadOnlyInstanceDescriptor[_T]", _T]:
        ...