]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
support renamed symbols in annotation scans
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Nov 2022 15:04:13 +0000 (11:04 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 4 Nov 2022 17:38:06 +0000 (13:38 -0400)
commitc0b8bdcaf020e8d043b9f9bce3e53d19e4fb79a0
treeceeb184a053a61c93428de120052f3a0d27a879d
parentb96321ae79a0366c33ca739e6e67aaf5f4420db4
support renamed symbols in annotation scans

Added support in ORM declarative annotations for class names specified for
:func:`_orm.relationship`, as well as the name of the :class:`_orm.Mapped`
symbol itself, to be different names than their direct class name, to
support scenarios such as where :class:`_orm.Mapped` is imported as
``from sqlalchemy.orm import Mapped as M``, or where related class names
are imported with an alternate name in a similar fashion. Additionally, a
target class name given as the lead argument for :func:`_orm.relationship`
will always supersede the name given in the left hand annotation, so that
otherwise un-importable names that also don't match the class name can
still be used in annotations.

Fixes: #8759
Change-Id: I74a00de7e1a45bf62dad50fd385bb75cf343f9f3
doc/build/changelog/unreleased_20/8759.rst [new file with mode: 0644]
lib/sqlalchemy/orm/relationships.py
lib/sqlalchemy/orm/util.py
lib/sqlalchemy/util/typing.py
test/orm/declarative/test_tm_future_annotations.py
test/orm/declarative/test_typed_mapping.py