From: Yurii Karabas <1998uriyyo@gmail.com> Date: Wed, 17 Jan 2024 16:26:31 +0000 (+0200) Subject: Remove redundant type alias X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=430785c8a04a48fe96ce35b4f4e08476700c1f79;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Remove redundant type alias --- diff --git a/lib/sqlalchemy/engine/_py_row.py b/lib/sqlalchemy/engine/_py_row.py index 4e1dd7d430..94ba85f2c2 100644 --- a/lib/sqlalchemy/engine/_py_row.py +++ b/lib/sqlalchemy/engine/_py_row.py @@ -18,10 +18,11 @@ from typing import Optional from typing import Tuple from typing import Type +from ..util.typing import TupleAny + if typing.TYPE_CHECKING: from .result import _KeyType from .result import _ProcessorsType - from .result import _RawRowType from .result import _TupleGetterType from .result import ResultMetaData @@ -33,14 +34,14 @@ class BaseRow: _parent: ResultMetaData _key_to_index: Mapping[_KeyType, int] - _data: _RawRowType + _data: TupleAny def __init__( self, parent: ResultMetaData, processors: Optional[_ProcessorsType], key_to_index: Mapping[_KeyType, int], - data: _RawRowType, + data: TupleAny, ): """Row objects are constructed by CursorResult objects.""" object.__setattr__(self, "_parent", parent) diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index c58231c16c..473830f317 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -73,20 +73,18 @@ _RowData = Union[Row[Unpack[TupleAny]], RowMapping, Any] "rows" that different result objects return, including row, row mapping, and scalar values""" -_RawRowType = Tuple[Any, ...] -"""represents the kind of row we get from a DBAPI cursor""" _R = TypeVar("_R", bound=_RowData) _T = TypeVar("_T", bound=Any) _Ts = TypeVarTuple("_Ts") -_InterimRowType = Union[_R, _RawRowType] +_InterimRowType = Union[_R, TupleAny] """a catchall "anything" kind of return type that can be applied across all the result types """ -_InterimSupportsScalarsRowType = Union[Row[Unpack[_RawRowType]], Any] +_InterimSupportsScalarsRowType = Union[Row[Unpack[TupleAny]], Any] _ProcessorsType = Sequence[Optional["_ResultProcessorType[Any]"]] _TupleGetterType = Callable[[Sequence[Any]], Sequence[Any]] @@ -333,9 +331,6 @@ class SimpleResultMetaData(ResultMetaData): _tuplefilter=_tuplefilter, ) - 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: if int in key.__class__.__mro__: key = self._keys[key] @@ -398,7 +393,7 @@ class SimpleResultMetaData(ResultMetaData): def result_tuple( fields: Sequence[str], extra: Optional[Any] = None -) -> Callable[[Iterable[Any]], Row[Unpack[_RawRowType]]]: +) -> Callable[[Iterable[Any]], Row[Unpack[TupleAny]]]: parent = SimpleResultMetaData(fields, extra) return functools.partial( Row, parent, parent._effective_processors, parent._key_to_index @@ -472,7 +467,7 @@ class ResultInternal(InPlaceGenerative, Generic[_R]): processors: Optional[_ProcessorsType], key_to_index: Mapping[_KeyType, int], scalar_obj: Any, - ) -> Row[Unpack[_RawRowType]]: + ) -> Row[Unpack[TupleAny]]: return _proc( metadata, processors, key_to_index, (scalar_obj,) ) @@ -1142,12 +1137,12 @@ class Result(_WithKeys, ResultInternal[Row[Unpack[_Ts]]]): return self._column_slices(col_expressions) @overload - def scalars(self: Result[_T, Unpack[_RawRowType]]) -> ScalarResult[_T]: + def scalars(self: Result[_T, Unpack[TupleAny]]) -> ScalarResult[_T]: ... @overload def scalars( - self: Result[_T, Unpack[_RawRowType]], index: Literal[0] + self: Result[_T, Unpack[TupleAny]], index: Literal[0] ) -> ScalarResult[_T]: ... @@ -1608,8 +1603,8 @@ class Result(_WithKeys, ResultInternal[Row[Unpack[_Ts]]]): return FrozenResult(self) def merge( - self, *others: Result[Unpack[_RawRowType]] - ) -> MergedResult[Unpack[_RawRowType]]: + self, *others: Result[Unpack[TupleAny]] + ) -> MergedResult[Unpack[TupleAny]]: """Merge this :class:`_engine.Result` with other compatible result objects. @@ -1749,7 +1744,7 @@ class ScalarResult(FilterResult[_R]): _post_creational_filter: Optional[Callable[[Any], Any]] def __init__( - self, real_result: Result[Unpack[_RawRowType]], index: _KeyIndexType + self, real_result: Result[Unpack[TupleAny]], index: _KeyIndexType ): self._real_result = real_result @@ -2043,7 +2038,7 @@ class MappingResult(_WithKeys, FilterResult[RowMapping]): _post_creational_filter = operator.attrgetter("_mapping") - def __init__(self, result: Result[Unpack[_RawRowType]]): + def __init__(self, result: Result[Unpack[TupleAny]]): self._real_result = result self._unique_filter_state = result._unique_filter_state self._metadata = result._metadata