--- /dev/null
+.. change::
+ :tags: bug, engine
+ :tickets: 10093
+
+ Renamed :attr:`_result.Row.t` and :meth:`_result.Row.tuple` to
+ :attr:`_result.Row._t` and :meth:`_result.Row._tuple`; this is to suit the
+ policy that all methods and pre-defined attributes on :class:`.Row` should
+ be in the style of Python standard library ``namedtuple`` where all fixed
+ names have a leading underscore, to avoid name conflicts with existing
+ column names. The previous method/attribute is now deprecated and will
+ emit a deprecation warning.
from typing import Union
from ..sql import util as sql_util
+from ..util import deprecated
from ..util._has_cy import HAS_CYEXTENSION
if TYPE_CHECKING or not HAS_CYEXTENSION:
def __delattr__(self, name: str) -> NoReturn:
raise AttributeError("can't delete attribute")
- def tuple(self) -> _TP:
+ def _tuple(self) -> _TP:
"""Return a 'tuple' form of this :class:`.Row`.
At runtime, this method returns "self"; the :class:`.Row` object is
``Tuple`` datatype that contains typing information about individual
elements, supporting typed unpacking and attribute access.
- .. versionadded:: 2.0
+ .. versionadded:: 2.0.19 - The :meth:`.Row._tuple` method supersedes
+ the previous :meth:`.Row.tuple` method, which is now underscored
+ to avoid name conflicts with column names in the same way as other
+ named-tuple methods on :class:`.Row`.
.. seealso::
+ :attr:`.Row._t` - shorthand attribute notation
+
:meth:`.Result.tuples`
+
"""
return self # type: ignore
- @property
- def t(self) -> _TP:
- """a synonym for :attr:`.Row.tuple`
+ @deprecated(
+ "2.0.19",
+ "The :meth:`.Row.tuple` method is deprecated in favor of "
+ ":meth:`.Row._tuple`; all :class:`.Row` "
+ "methods and library-level attributes are intended to be underscored "
+ "to avoid name conflicts. Please use :meth:`Row._tuple`.",
+ )
+ def tuple(self) -> _TP:
+ """Return a 'tuple' form of this :class:`.Row`.
.. versionadded:: 2.0
- .. seealso::
+ """
+ return self._tuple()
- :meth:`.Result.t`
+ @property
+ def _t(self) -> _TP:
+ """A synonym for :meth:`.Row._tuple`.
+ .. versionadded:: 2.0.19 - The :attr:`.Row._t` attribute supersedes
+ the previous :attr:`.Row.t` attribute, which is now underscored
+ to avoid name conflicts with column names in the same way as other
+ named-tuple methods on :class:`.Row`.
+
+ .. seealso::
+
+ :attr:`.Result.t`
"""
return self # type: ignore
+ @property
+ @deprecated(
+ "2.0.19",
+ "The :attr:`.Row.t` attribute is deprecated in favor of "
+ ":attr:`.Row._t`; all :class:`.Row` "
+ "methods and library-level attributes are intended to be underscored "
+ "to avoid name conflicts. Please use :attr:`Row._t`.",
+ )
+ def t(self) -> _TP:
+ """A synonym for :meth:`.Row._tuple`.
+
+ .. versionadded:: 2.0
+
+ """
+ return self._t
+
@property
def _mapping(self) -> RowMapping:
"""Return a :class:`.RowMapping` for this :class:`.Row`.
{"user_id": 9, "user_name": "fred"},
],
)
- r = connection.execute(users.select().order_by(users.c.user_id))
- eq_([row.t for row in r], [(7, "jack"), (8, "ed"), (9, "fred")])
+ r = connection.execute(users.select().order_by(users.c.user_id)).all()
+ exp = [(7, "jack"), (8, "ed"), (9, "fred")]
+ eq_([row._t for row in r], exp)
+ eq_([row._tuple() for row in r], exp)
+ with assertions.expect_deprecated(
+ r"The Row.t attribute is deprecated in favor of Row._t"
+ ):
+ eq_([row.t for row in r], exp)
+
+ with assertions.expect_deprecated(
+ r"The Row.tuple\(\) method is deprecated in "
+ r"favor of Row._tuple\(\)"
+ ):
+ eq_([row.tuple() for row in r], exp)
def test_row_next(self, connection):
users = self.tables.users