summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/util/typing.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2022-03-08 17:14:41 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2022-03-13 15:29:20 -0400
commit769fa67d842035dd852ab8b6a26ea3f110a51131 (patch)
tree5c121caca336071091c6f5ea4c54743c92d6458a /lib/sqlalchemy/util/typing.py
parent77fc8216a74e6b2d0efc6591c6c735687bd10002 (diff)
downloadsqlalchemy-769fa67d842035dd852ab8b6a26ea3f110a51131.tar.gz
pep-484: sqlalchemy.sql pass one
sqlalchemy.sql will require many passes to get all modules even gradually typed. Will have to pick and choose what modules can be strictly typed vs. which can be gradual. in this patch, emphasis is on visitors.py, cache_key.py, annotations.py for strict typing, compiler.py is on gradual typing but has much more structure, in particular where it connects with the outside world. The work within compiler.py also reached back out to engine/cursor.py , default.py quite a bit. References: #6810 Change-Id: I6e8a29f6013fd216e43d45091bc193f8be0368fd
Diffstat (limited to 'lib/sqlalchemy/util/typing.py')
-rw-r--r--lib/sqlalchemy/util/typing.py24
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/sqlalchemy/util/typing.py b/lib/sqlalchemy/util/typing.py
index 160eabd85..c089616e4 100644
--- a/lib/sqlalchemy/util/typing.py
+++ b/lib/sqlalchemy/util/typing.py
@@ -3,10 +3,11 @@ from __future__ import annotations
import sys
import typing
from typing import Any
-from typing import Callable # noqa
from typing import cast
from typing import Dict
from typing import ForwardRef
+from typing import Iterable
+from typing import Tuple
from typing import Type
from typing import TypeVar
from typing import Union
@@ -16,6 +17,11 @@ from typing_extensions import NotRequired as NotRequired # noqa
from . import compat
_T = TypeVar("_T", bound=Any)
+_KT = TypeVar("_KT")
+_KT_co = TypeVar("_KT_co", covariant=True)
+_KT_contra = TypeVar("_KT_contra", contravariant=True)
+_VT = TypeVar("_VT")
+_VT_co = TypeVar("_VT_co", covariant=True)
Self = TypeVar("Self", bound=Any)
@@ -45,6 +51,18 @@ else:
from typing_extensions import Protocol as Protocol # noqa F401
from typing_extensions import TypedDict as TypedDict # noqa F401
+# copied from TypeShed, required in order to implement
+# MutableMapping.update()
+
+
+class SupportsKeysAndGetItem(Protocol[_KT, _VT_co]):
+ def keys(self) -> Iterable[_KT]:
+ ...
+
+ def __getitem__(self, __k: _KT) -> _VT_co:
+ ...
+
+
# work around https://github.com/microsoft/pyright/issues/3025
_LiteralStar = Literal["*"]
@@ -120,7 +138,9 @@ def make_union_type(*types):
return cast(Any, Union).__getitem__(types)
-def expand_unions(type_, include_union=False, discard_none=False):
+def expand_unions(
+ type_: Type[Any], include_union: bool = False, discard_none: bool = False
+) -> Tuple[Type[Any], ...]:
"""Return a type as as a tuple of individual types, expanding for
``Union`` types."""