From: Yurii Karabas <1998uriyyo@gmail.com> Date: Sat, 16 Dec 2023 14:15:44 +0000 (+0200) Subject: Add depracation for old tuple methods X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d582fc5892f1f093c6fc247de80e5971bfc49c96;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Add depracation for old tuple methods --- diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index 2b9f0282cc..90c49a6705 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -40,6 +40,7 @@ from .. import util from ..sql.base import _generative from ..sql.base import HasMemoized from ..sql.base import InPlaceGenerative +from ..util import deprecated from ..util import HasMemoized_ro_memoized_attribute from ..util import NONE_SET from ..util._has_cy import HAS_CYEXTENSION @@ -1232,6 +1233,11 @@ class Result(_WithKeys, ResultInternal[Row[Unpack[_Ts]]]): return MappingResult(self) @property + @deprecated( + "2.1.0", + "The :attr:`.Result.t` method is deprecated, :class:`.Row` " + "now behaves like a tuple and can unpack types directly.", + ) def t(self) -> TupleResult[Tuple[Unpack[_Ts]]]: """Apply a "typed tuple" typing filter to returned rows. @@ -1243,6 +1249,11 @@ class Result(_WithKeys, ResultInternal[Row[Unpack[_Ts]]]): """ return self # type: ignore + @deprecated( + "2.1.0", + "The :method:`.Result.tuples` method is deprecated, :class:`.Row` " + "now behaves like a tuple and can unpack types directly.", + ) def tuples(self) -> TupleResult[Tuple[Unpack[_Ts]]]: """Apply a "typed tuple" typing filter to returned rows. diff --git a/lib/sqlalchemy/engine/row.py b/lib/sqlalchemy/engine/row.py index e164b45a71..d2aa1c497e 100644 --- a/lib/sqlalchemy/engine/row.py +++ b/lib/sqlalchemy/engine/row.py @@ -88,6 +88,11 @@ class Row(BaseRow, _RowBase[Unpack[_Ts]], Generic[Unpack[_Ts]]): def __delattr__(self, name: str) -> NoReturn: raise AttributeError("can't delete attribute") + @deprecated( + "2.1.0", + "The :meth:`.Row._tuple` method is deprecated, :class:`.Row` " + "now behaves like a tuple and can unpack types directly.", + ) def _tuple(self) -> Tuple[Unpack[_Ts]]: """Return a 'tuple' form of this :class:`.Row`. @@ -128,6 +133,11 @@ class Row(BaseRow, _RowBase[Unpack[_Ts]], Generic[Unpack[_Ts]]): return self._tuple() @property + @deprecated( + "2.1.0", + "The :attr:`.Row._t` attribute is deprecated, :class:`.Row` " + "now behaves like a tuple and can unpack types directly.", + ) def _t(self) -> Tuple[Unpack[_Ts]]: """A synonym for :meth:`.Row._tuple`. diff --git a/lib/sqlalchemy/ext/asyncio/result.py b/lib/sqlalchemy/ext/asyncio/result.py index 4c093aa17c..5467ed4c8f 100644 --- a/lib/sqlalchemy/ext/asyncio/result.py +++ b/lib/sqlalchemy/ext/asyncio/result.py @@ -28,6 +28,7 @@ from ...engine.result import ResultMetaData from ...engine.row import Row from ...engine.row import RowMapping from ...sql.base import _generative +from ...util import deprecated from ...util.concurrency import greenlet_spawn from ...util.typing import Literal from ...util.typing import Self @@ -105,6 +106,11 @@ class AsyncResult(_WithKeys, AsyncCommon[Row[Unpack[_Ts]]]): ) @property + @deprecated( + "2.1.0", + "The :attr:`.AsyncResult.t` attribute is deprecated, :class:`.Row` " + "now behaves like a tuple and can unpack types directly.", + ) def t(self) -> AsyncTupleResult[Tuple[Unpack[_Ts]]]: """Apply a "typed tuple" typing filter to returned rows. @@ -116,6 +122,12 @@ class AsyncResult(_WithKeys, AsyncCommon[Row[Unpack[_Ts]]]): """ return self # type: ignore + @deprecated( + "2.1.0", + "The :method:`.AsyncResult.tuples` method is deprecated, " + ":class:`.Row` now behaves like a tuple and can unpack types " + "directly.", + ) def tuples(self) -> AsyncTupleResult[Tuple[Unpack[_Ts]]]: """Apply a "typed tuple" typing filter to returned rows. diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index 62966c7870..b4a30128d1 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -90,6 +90,7 @@ from ..sql.selectable import HasPrefixes from ..sql.selectable import HasSuffixes from ..sql.selectable import LABEL_STYLE_TABLENAME_PLUS_COL from ..sql.selectable import SelectLabelStyle +from ..util import deprecated from ..util.typing import Literal from ..util.typing import Self from ..util.typing import TypeVarTuple @@ -297,6 +298,11 @@ class Query( for ent in util.to_list(entities) ] + @deprecated( + "2.1.0", + "The :method:`.Query.tuples` method is deprecated, :class:`.Row` " + "now behaves like a tuple and can unpack types directly.", + ) def tuples(self: Query[_O]) -> Query[Tuple[_O]]: """return a tuple-typed form of this :class:`.Query`.