as a context manager were not preserved, indicating :class:`_engine.Result`
in all cases rather than the specific :class:`_engine.Result` sub-type.
Pull request courtesy Martin Baláž.
+
+.. change::
+ :tags: typing, bug
+ :tickets: 9150
+
+ Fixed issue where using the :paramref:`_orm.relationship.remote_side`
+ and similar parameters, passing an annotated declarative object typed as
+ :class:`_orm.Mapped`, would not be accepted by the type checker.
ORMBackrefArgument = Union[str, Tuple[str, Dict[str, Any]]]
_ORMColCollectionElement = Union[
- ColumnClause[Any], _HasClauseElement, roles.DMLColumnRole
+ ColumnClause[Any], _HasClauseElement, roles.DMLColumnRole, "Mapped[Any]"
]
_ORMColCollectionArgument = Union[
str,
"""this suite experiments with other kinds of relationship syntaxes.
"""
+from __future__ import annotations
+
import typing
from typing import List
from typing import Optional
user_style_two: Mapped["User"] = relationship()
+class SelfReferential(Base):
+ """test for #9150"""
+
+ __tablename__ = "MyTable"
+
+ idx: Mapped[int] = mapped_column(Integer, primary_key=True)
+ mytable_id: Mapped[int] = mapped_column(ForeignKey("MyTable.idx"))
+
+ not_anno = mapped_column(Integer)
+
+ selfref_1: Mapped[Optional[SelfReferential]] = relationship(
+ remote_side=idx
+ )
+ selfref_2: Mapped[Optional[SelfReferential]] = relationship(
+ foreign_keys=mytable_id
+ )
+
+ selfref_3: Mapped[Optional[SelfReferential]] = relationship(
+ remote_side=not_anno
+ )
+
+
if typing.TYPE_CHECKING:
# EXPECTED_RE_TYPE: sqlalchemy.*.InstrumentedAttribute\[Union\[builtins.str, None\]\]
reveal_type(User.extra)