From 0042076f5db0cdeceee51b5ce32d76cc54c2af69 Mon Sep 17 00:00:00 2001 From: Simon Schiele Date: Wed, 30 Nov 2022 08:40:50 -0500 Subject: Add "compare" on dataclass fields Added :paramref:`_orm.mapped_column.compare` parameter to relevant ORM attribute constructs including :func:`_orm.mapped_column`, :func:`_orm.relationship` etc. to provide for the Python dataclasses ``compare`` parameter on ``field()``, when using the :ref:`orm_declarative_native_dataclasses` feature. Pull request courtesy Simon Schiele. Added an additional case for associationproxy into test_dc_transforms.py -> test_attribute_options Fixes: #8905 Closes: #8906 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/8906 Pull-request-sha: ea9a53d2ca60befdd0c570013c0e57a78c11dd4a Change-Id: I390d043b06c1d668242325ef86e2f7b7dbfac442 --- lib/sqlalchemy/ext/associationproxy.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib/sqlalchemy/ext') diff --git a/lib/sqlalchemy/ext/associationproxy.py b/lib/sqlalchemy/ext/associationproxy.py index 15193e563..4d38ac536 100644 --- a/lib/sqlalchemy/ext/associationproxy.py +++ b/lib/sqlalchemy/ext/associationproxy.py @@ -94,6 +94,7 @@ def association_proxy( repr: Union[_NoArg, bool] = _NoArg.NO_ARG, # noqa: A002 default: Optional[Any] = _NoArg.NO_ARG, default_factory: Union[_NoArg, Callable[[], _T]] = _NoArg.NO_ARG, + compare: Union[_NoArg, bool] = _NoArg.NO_ARG, kw_only: Union[_NoArg, bool] = _NoArg.NO_ARG, ) -> AssociationProxy[Any]: r"""Return a Python property implementing a view of a target @@ -174,6 +175,13 @@ def association_proxy( .. versionadded:: 2.0.0b4 + :param compare: Specific to + :ref:`orm_declarative_native_dataclasses`, indicates if this field + should be included in comparison operations when generating the + ``__eq__()`` and ``__ne__()`` methods for the mapped class. + + .. versionadded:: 2.0.0b4 + :param kw_only: Specific to :ref:`orm_declarative_native_dataclasses`, indicates if this field should be marked as keyword-only when generating the ``__init__()`` method as generated by the dataclass process. @@ -218,7 +226,7 @@ def association_proxy( info=info, cascade_scalar_deletes=cascade_scalar_deletes, attribute_options=_AttributeOptions( - init, repr, default, default_factory, kw_only + init, repr, default, default_factory, compare, kw_only ), ) -- cgit v1.2.1