]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
update typing
authorYurii Karabas <1998uriyyo@gmail.com>
Tue, 14 Nov 2023 17:04:38 +0000 (19:04 +0200)
committerYurii Karabas <1998uriyyo@gmail.com>
Tue, 14 Nov 2023 17:04:38 +0000 (19:04 +0200)
lib/sqlalchemy/engine/result.py
lib/sqlalchemy/ext/asyncio/scoping.py
lib/sqlalchemy/ext/asyncio/session.py
lib/sqlalchemy/orm/descriptor_props.py
lib/sqlalchemy/orm/mapper.py
lib/sqlalchemy/orm/scoping.py
lib/sqlalchemy/orm/session.py
lib/sqlalchemy/orm/state.py
lib/sqlalchemy/orm/util.py

index 579528d966ead2a9c42a010683958d6ea358de85..239af9895140bc266707908b7892456397fb8d38 100644 (file)
@@ -66,7 +66,7 @@ _KeyMapRecType = Any
 _KeyMapType = Mapping[_KeyType, _KeyMapRecType]
 
 
-_RowData = Union[Row[Any], RowMapping, Any]
+_RowData = Union[Row[Unpack[Tuple[Any, ...]]], RowMapping, Any]
 """A generic form of "row" that accommodates for the different kinds of
 "rows" that different result objects return, including row, row mapping, and
 scalar values"""
@@ -85,7 +85,7 @@ across all the result types
 
 """
 
-_InterimSupportsScalarsRowType = Union[Row[Any], Any]
+_InterimSupportsScalarsRowType = Union[Row[Unpack[_RawRowType]], Any]
 
 _ProcessorsType = Sequence[Optional["_ResultProcessorType[Any]"]]
 _TupleGetterType = Callable[[Sequence[Any]], Sequence[Any]]
@@ -171,7 +171,7 @@ class ResultMetaData:
 
     def _getter(
         self, key: Any, raiseerr: bool = True
-    ) -> Optional[Callable[[Row[Any]], Any]]:
+    ) -> Optional[Callable[[Row[Unpack[Tuple[Any, ...]]]], Any]]:
         index = self._index_for_key(key, raiseerr)
 
         if index is not None:
@@ -332,7 +332,7 @@ class SimpleResultMetaData(ResultMetaData):
             _tuplefilter=_tuplefilter,
         )
 
-    def _contains(self, value: Any, row: Row[Any]) -> bool:
+    def _contains(self, value: Any, row: Row[Unpack[_RawRowType]]) -> bool:
         return value in row._data
 
     def _index_for_key(self, key: Any, raiseerr: bool = True) -> int:
@@ -429,20 +429,24 @@ class ResultInternal(InPlaceGenerative, Generic[_R]):
 
     _source_supports_scalars: bool
 
-    def _fetchiter_impl(self) -> Iterator[_InterimRowType[Row[Any]]]:
+    def _fetchiter_impl(
+        self,
+    ) -> Iterator[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         raise NotImplementedError()
 
     def _fetchone_impl(
         self, hard_close: bool = False
-    ) -> Optional[_InterimRowType[Row[Any]]]:
+    ) -> Optional[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         raise NotImplementedError()
 
     def _fetchmany_impl(
         self, size: Optional[int] = None
-    ) -> List[_InterimRowType[Row[Any]]]:
+    ) -> List[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         raise NotImplementedError()
 
-    def _fetchall_impl(self) -> List[_InterimRowType[Row[Any]]]:
+    def _fetchall_impl(
+        self,
+    ) -> List[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         raise NotImplementedError()
 
     def _soft_close(self, hard: bool = False) -> None:
@@ -467,7 +471,7 @@ class ResultInternal(InPlaceGenerative, Generic[_R]):
                     processors: Optional[_ProcessorsType],
                     key_to_index: Mapping[_KeyType, int],
                     scalar_obj: Any,
-                ) -> Row[Any]:
+                ) -> Row[Unpack[_RawRowType]]:
                     return _proc(
                         metadata, processors, key_to_index, (scalar_obj,)
                     )
@@ -491,7 +495,9 @@ class ResultInternal(InPlaceGenerative, Generic[_R]):
 
             fixed_tf = tf
 
-            def make_row(row: _InterimRowType[Row[Any]]) -> _R:
+            def make_row(
+                row: _InterimRowType[Row[Unpack[Tuple[Any, ...]]]]
+            ) -> _R:
                 return _make_row_orig(fixed_tf(row))
 
         else:
@@ -503,7 +509,9 @@ class ResultInternal(InPlaceGenerative, Generic[_R]):
             _log_row = real_result._row_logging_fn
             _make_row = make_row
 
-            def make_row(row: _InterimRowType[Row[Any]]) -> _R:
+            def make_row(
+                row: _InterimRowType[Row[Unpack[Tuple[Any, ...]]]]
+            ) -> _R:
                 return _log_row(_make_row(row))  # type: ignore
 
         return make_row
@@ -948,7 +956,9 @@ class Result(_WithKeys, ResultInternal[Row[Unpack[_Ts]]]):
 
     __slots__ = ("_metadata", "__dict__")
 
-    _row_logging_fn: Optional[Callable[[Row[Any]], Row[Any]]] = None
+    _row_logging_fn: Optional[
+        Callable[[Row[Unpack[Tuple[Any, ...]]]], Row[Unpack[Tuple[Any, ...]]]]
+    ] = None
 
     _source_supports_scalars: bool = False
 
@@ -1183,7 +1193,7 @@ class Result(_WithKeys, ResultInternal[Row[Unpack[_Ts]]]):
 
     def _getter(
         self, key: _KeyIndexType, raiseerr: bool = True
-    ) -> Optional[Callable[[Row[Any]], Any]]:
+    ) -> Optional[Callable[[Row[Unpack[Tuple[Any, ...]]]], Any]]:
         """return a callable that will retrieve the given key from a
         :class:`_engine.Row`.
 
@@ -1696,20 +1706,24 @@ class FilterResult(ResultInternal[_R]):
     def _attributes(self) -> Dict[Any, Any]:
         return self._real_result._attributes
 
-    def _fetchiter_impl(self) -> Iterator[_InterimRowType[Row[Any]]]:
+    def _fetchiter_impl(
+        self,
+    ) -> Iterator[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         return self._real_result._fetchiter_impl()
 
     def _fetchone_impl(
         self, hard_close: bool = False
-    ) -> Optional[_InterimRowType[Row[Any]]]:
+    ) -> Optional[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         return self._real_result._fetchone_impl(hard_close=hard_close)
 
-    def _fetchall_impl(self) -> List[_InterimRowType[Row[Any]]]:
+    def _fetchall_impl(
+        self,
+    ) -> List[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         return self._real_result._fetchall_impl()
 
     def _fetchmany_impl(
         self, size: Optional[int] = None
-    ) -> List[_InterimRowType[Row[Any]]]:
+    ) -> List[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         return self._real_result._fetchmany_impl(size=size)
 
 
@@ -2292,7 +2306,7 @@ class IteratorResult(Result[Unpack[_Ts]]):
 
     def _fetchone_impl(
         self, hard_close: bool = False
-    ) -> Optional[_InterimRowType[Row[Any]]]:
+    ) -> Optional[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         if self._hard_closed:
             self._raise_hard_closed()
 
@@ -2303,7 +2317,9 @@ class IteratorResult(Result[Unpack[_Ts]]):
         else:
             return row
 
-    def _fetchall_impl(self) -> List[_InterimRowType[Row[Any]]]:
+    def _fetchall_impl(
+        self,
+    ) -> List[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         if self._hard_closed:
             self._raise_hard_closed()
         try:
@@ -2313,7 +2329,7 @@ class IteratorResult(Result[Unpack[_Ts]]):
 
     def _fetchmany_impl(
         self, size: Optional[int] = None
-    ) -> List[_InterimRowType[Row[Any]]]:
+    ) -> List[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         if self._hard_closed:
             self._raise_hard_closed()
 
@@ -2375,7 +2391,7 @@ class ChunkedIteratorResult(IteratorResult[Unpack[_Ts]]):
 
     def _fetchmany_impl(
         self, size: Optional[int] = None
-    ) -> List[_InterimRowType[Row[Any]]]:
+    ) -> List[_InterimRowType[Row[Unpack[Tuple[Any, ...]]]]]:
         if self.dynamic_yield_per:
             self.iterator = itertools.chain.from_iterable(self.chunks(size))
         return super()._fetchmany_impl(size=size)
index 3e1f7ecb3381095331a81a29cab49c1a976a7f81..0f7f93ecec95c9ea636a0192c54c6ed8c9b8d3ae 100644 (file)
@@ -1594,7 +1594,7 @@ class async_scoped_session(Generic[_AS]):
         ident: Union[Any, Tuple[Any, ...]] = None,
         *,
         instance: Optional[Any] = None,
-        row: Optional[Union[Row[Any], RowMapping]] = None,
+        row: Optional[Union[Row[Unpack[Tuple[Any, ...]]], RowMapping]] = None,
         identity_token: Optional[Any] = None,
     ) -> _IdentityKeyType[Any]:
         r"""Return an identity key.
index 36a73ef6aabd46ab7dcbe44d284397350f44ab8a..6a78a0978e424289616fe1c9cba679e2df1d0d45 100644 (file)
@@ -1591,7 +1591,7 @@ class AsyncSession(ReversibleProxy[Session]):
         ident: Union[Any, Tuple[Any, ...]] = None,
         *,
         instance: Optional[Any] = None,
-        row: Optional[Union[Row[Any], RowMapping]] = None,
+        row: Optional[Union[Row[Unpack[Tuple[Any, ...]]], RowMapping]] = None,
         identity_token: Optional[Any] = None,
     ) -> _IdentityKeyType[Any]:
         r"""Return an identity key.
index c1fe9de85cab3cee69531498c0dd52f7a1544f07..5880aad06ac70123a471864814a0219ffde1f6f3 100644 (file)
@@ -56,6 +56,8 @@ from ..sql.elements import BindParameter
 from ..util.typing import is_fwd_ref
 from ..util.typing import is_pep593
 from ..util.typing import typing_get_args
+from ..util.typing import Unpack
+
 
 if typing.TYPE_CHECKING:
     from ._typing import _InstanceDict
@@ -714,10 +716,10 @@ class CompositeProperty(
         def create_row_processor(
             self,
             query: Select[Any],
-            procs: Sequence[Callable[[Row[Any]], Any]],
+            procs: Sequence[Callable[[Row[Unpack[Tuple[Any, ...]]]], Any]],
             labels: Sequence[str],
-        ) -> Callable[[Row[Any]], Any]:
-            def proc(row: Row[Any]) -> Any:
+        ) -> Callable[[Row[Unpack[Tuple[Any, ...]]]], Any]:
+            def proc(row: Row[Unpack[Tuple[Any, ...]]]) -> Any:
                 return self.property.composite_class(
                     *[proc(row) for proc in procs]
                 )
index b686996370c82e1be8ed2fa24f588960724b18c5..1228931a749ccaea4543d5479db83be2acf0e878 100644 (file)
@@ -89,6 +89,7 @@ from ..sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL
 from ..util import HasMemoized
 from ..util import HasMemoized_ro_memoized_attribute
 from ..util.typing import Literal
+from ..util.typing import Unpack
 
 if TYPE_CHECKING:
     from ._typing import _IdentityKeyType
@@ -3428,7 +3429,7 @@ class Mapper(
 
     def identity_key_from_row(
         self,
-        row: Optional[Union[Row[Any], RowMapping]],
+        row: Optional[Union[Row[Unpack[Tuple[Any, ...]]], RowMapping]],
         identity_token: Optional[Any] = None,
         adapter: Optional[ORMAdapter] = None,
     ) -> _IdentityKeyType[_O]:
index 65ab1abef708f67cf64a8c1a9e40cbcc134d430b..5b5dc655a036b9db2d93e58c6b9d722874b5cda4 100644 (file)
@@ -2154,7 +2154,7 @@ class scoped_session(Generic[_S]):
         ident: Union[Any, Tuple[Any, ...]] = None,
         *,
         instance: Optional[Any] = None,
-        row: Optional[Union[Row[Any], RowMapping]] = None,
+        row: Optional[Union[Row[Unpack[Tuple[Any, ...]]], RowMapping]] = None,
         identity_token: Optional[Any] = None,
     ) -> _IdentityKeyType[Any]:
         r"""Return an identity key.
index 45925a6d9f26c8e184bdda3c9a125824a14fa99b..eb4330b17c4cc51f5dae4d87080cdea357fb518a 100644 (file)
@@ -226,7 +226,7 @@ class _SessionClassMethods:
         ident: Union[Any, Tuple[Any, ...]] = None,
         *,
         instance: Optional[Any] = None,
-        row: Optional[Union[Row[Any], RowMapping]] = None,
+        row: Optional[Union[Row[Unpack[Tuple[Any, ...]]], RowMapping]] = None,
         identity_token: Optional[Any] = None,
     ) -> _IdentityKeyType[Any]:
         """Return an identity key.
index d9e1f854d77e8bba58ee4f962ebe9cda4c9aba63..d142f075c4e8bbb9ed77bb48a4eb6d67718289cd 100644 (file)
@@ -46,6 +46,7 @@ from .. import inspection
 from .. import util
 from ..util.typing import Literal
 from ..util.typing import Protocol
+from ..util.typing import Unpack
 
 if TYPE_CHECKING:
     from ._typing import _IdentityKeyType
@@ -93,7 +94,10 @@ class _InstallLoaderCallableProto(Protocol[_O]):
     """
 
     def __call__(
-        self, state: InstanceState[_O], dict_: _InstanceDict, row: Row[Any]
+        self,
+        state: InstanceState[_O],
+        dict_: _InstanceDict,
+        row: Row[Unpack[Tuple[Any, ...]]],
     ) -> None:
         ...
 
@@ -673,7 +677,9 @@ class InstanceState(interfaces.InspectionAttrInfo, Generic[_O]):
             fixed_impl = impl
 
             def _set_callable(
-                state: InstanceState[_O], dict_: _InstanceDict, row: Row[Any]
+                state: InstanceState[_O],
+                dict_: _InstanceDict,
+                row: Row[Unpack[Tuple[Any, ...]]],
             ) -> None:
                 if "callables" not in state.__dict__:
                     state.callables = {}
@@ -685,7 +691,9 @@ class InstanceState(interfaces.InspectionAttrInfo, Generic[_O]):
         else:
 
             def _set_callable(
-                state: InstanceState[_O], dict_: _InstanceDict, row: Row[Any]
+                state: InstanceState[_O],
+                dict_: _InstanceDict,
+                row: Row[Unpack[Tuple[Any, ...]]],
             ) -> None:
                 if "callables" not in state.__dict__:
                     state.callables = {}
index ea2f1a12e9365d562aace63b6c2a4e18476c5813..ae915ce3b2b1a7288b36b9038c8dd381b8f45aa5 100644 (file)
@@ -93,6 +93,7 @@ from ..util.typing import is_origin_of_cls
 from ..util.typing import Literal
 from ..util.typing import Protocol
 from ..util.typing import typing_get_origin
+from ..util.typing import Unpack
 
 if typing.TYPE_CHECKING:
     from ._typing import _EntityType
@@ -426,7 +427,7 @@ def identity_key(
     ident: Union[Any, Tuple[Any, ...]] = None,
     *,
     instance: Optional[_T] = None,
-    row: Optional[Union[Row[Any], RowMapping]] = None,
+    row: Optional[Union[Row[Unpack[Tuple[Any, ...]]], RowMapping]] = None,
     identity_token: Optional[Any] = None,
 ) -> _IdentityKeyType[_T]:
     r"""Generate "identity key" tuples, as are used as keys in the
@@ -1722,9 +1723,9 @@ class Bundle(
     def create_row_processor(
         self,
         query: Select[Any],
-        procs: Sequence[Callable[[Row[Any]], Any]],
+        procs: Sequence[Callable[[Row[Unpack[Tuple[Any, ...]]]], Any]],
         labels: Sequence[str],
-    ) -> Callable[[Row[Any]], Any]:
+    ) -> Callable[[Row[Unpack[Tuple[Any, ...]]]], Any]:
         """Produce the "row processing" function for this :class:`.Bundle`.
 
         May be overridden by subclasses to provide custom behaviors when
@@ -1760,7 +1761,7 @@ class Bundle(
         """
         keyed_tuple = result_tuple(labels, [() for l in labels])
 
-        def proc(row: Row[Any]) -> Any:
+        def proc(row: Row[Unpack[Tuple[Any, ...]]]) -> Any:
             return keyed_tuple([proc(row) for proc in procs])
 
         return proc