]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
modernize hybrids and apply typing
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 16 Feb 2023 14:39:07 +0000 (09:39 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 16 Feb 2023 23:01:31 +0000 (18:01 -0500)
commit81993801dd39dd4a5973f8500e849f35ac07f2f3
tree570a577f1f97e50b0bb195973f4c1ef77f4b12cf
parent88c9463dc1114d493ed886a11705af714f27a221
modernize hybrids and apply typing

Improved the typing support for the :ref:`hybrids_toplevel`
extension, updated all documentation to use ORM Annotated Declarative
mappings, and added a new modifier called :attr:`.hybrid_property.inplace`.
This modifier provides a way to alter the state of a :class:`.hybrid_property`
**in place**, which is essentially what very early versions of hybrids
did, before SQLAlchemy version 1.2.0 :ticket:`3912` changed this to
remove in-place mutation.  This in-place mutation is now restored on an
**opt-in** basis to allow a single hybrid to have multiple methods
set up, without the need to name all the methods the same and without the
need to carefully "chain" differently-named methods in order to maintain
the composition.  Typing tools such as Mypy and Pyright do not allow
same-named methods on a class, so with this change a succinct method
of setting up hybrids with typing support is restored.

Change-Id: Iea88025f023428f9f006846d09fbb4be391f5ebb
References: #9321
doc/build/changelog/unreleased_20/9321.rst [new file with mode: 0644]
doc/build/changelog/whatsnew_20.rst
lib/sqlalchemy/ext/hybrid.py
lib/sqlalchemy/sql/_typing.py
lib/sqlalchemy/sql/selectable.py
test/ext/mypy/plain_files/hybrid_four.py [new file with mode: 0644]
test/ext/mypy/plain_files/hybrid_one.py
test/ext/mypy/plain_files/hybrid_three.py [new file with mode: 0644]
test/ext/mypy/plain_files/hybrid_two.py
test/ext/test_hybrid.py