]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commit
implement dataclass_transforms
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 18 Feb 2022 15:05:12 +0000 (10:05 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 20 May 2022 18:19:02 +0000 (14:19 -0400)
commita463b1109abb60fc85f8356f30c0351a4e2ed71e
treede8f96b7bce319fc0f19f56b302202ea3e4e91db
parent9e7bed9df601ead02fd96bf2fc787b23b536d2d6
implement dataclass_transforms

Implement a new means of creating a mapped dataclass where
instead of applying the `@dataclass` decorator distinctly,
the declarative process itself can create the dataclass.

MapperProperty and MappedColumn objects themselves take
the place of the dataclasses.Field object when constructing
the class.

The overall approach is made possible at the typing level
using pep-681 dataclass transforms [1].

This new approach should be able to completely supersede the
previous "dataclasses" approach of embedding metadata into
Field() objects, which remains a mutually exclusive declarative
setup style (mixing them introduces new issues that are not worth
solving).

[1] https://peps.python.org/pep-0681/#transform-descriptor-types-example

Fixes: #7642
Change-Id: I6ba88a87c5df38270317b4faf085904d91c8a63c
17 files changed:
lib/sqlalchemy/orm/__init__.py
lib/sqlalchemy/orm/_orm_constructors.py
lib/sqlalchemy/orm/decl_api.py
lib/sqlalchemy/orm/decl_base.py
lib/sqlalchemy/orm/descriptor_props.py
lib/sqlalchemy/orm/instrumentation.py
lib/sqlalchemy/orm/interfaces.py
lib/sqlalchemy/orm/properties.py
lib/sqlalchemy/orm/relationships.py
lib/sqlalchemy/orm/util.py
lib/sqlalchemy/testing/fixtures.py
lib/sqlalchemy/util/compat.py
lib/sqlalchemy/util/typing.py
pyproject.toml
setup.cfg
test/orm/declarative/test_dc_transforms.py [new file with mode: 0644]
test/orm/declarative/test_typed_mapping.py