From 69747f7173586cd937db1e2ad60343e490f8827f Mon Sep 17 00:00:00 2001 From: q0w <43147888+q0w@users.noreply.github.com> Date: Thu, 22 Aug 2024 15:55:35 +0300 Subject: [PATCH] 5.1: Deprecate CheckConstraint.check (#2331) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- django-stubs/db/models/constraints.pyi | 17 +++++++++++++++-- tests/assert_type/db/models/test_constraints.py | 2 +- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/django-stubs/db/models/constraints.pyi b/django-stubs/db/models/constraints.pyi index 7e68930aa..2d94b12ef 100644 --- a/django-stubs/db/models/constraints.pyi +++ b/django-stubs/db/models/constraints.pyi @@ -40,13 +40,26 @@ class BaseConstraint: class CheckConstraint(BaseConstraint): check: Q | BaseExpression + condition: Q | BaseExpression + + @overload + @deprecated("The check keyword argument is deprecated in favor of condition and will be removed in Django 6.0") def __init__( self, *, + name: str, check: Q | BaseExpression, + violation_error_code: str | None = None, + violation_error_message: _StrOrPromise | None = None, + ) -> None: ... + @overload + def __init__( + self, + *, name: str, - violation_error_code: str | None = ..., - violation_error_message: _StrOrPromise | None = ..., + condition: Q | BaseExpression, + violation_error_code: str | None = None, + violation_error_message: _StrOrPromise | None = None, ) -> None: ... class UniqueConstraint(BaseConstraint): diff --git a/tests/assert_type/db/models/test_constraints.py b/tests/assert_type/db/models/test_constraints.py index db0fce1a7..971675559 100644 --- a/tests/assert_type/db/models/test_constraints.py +++ b/tests/assert_type/db/models/test_constraints.py @@ -13,4 +13,4 @@ name="unique_mess", ) -CheckConstraint(name="less_than_constraint", check=LessThan[Any](F("months"), 1)) +CheckConstraint(name="less_than_constraint", check=LessThan[Any](F("months"), 1)) # pyright: ignore[reportDeprecated]