From: Anton Kovalevich Date: Fri, 18 Jun 2021 12:39:08 +0000 (+0300) Subject: Change API: drop properties, use regular methods instead X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dc6842f13688849a848e2ecbb81600e6edf8b3a9;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Change API: drop properties, use regular methods instead --- diff --git a/lib/sqlalchemy/dialects/mysql/expression.py b/lib/sqlalchemy/dialects/mysql/expression.py index 72718bacb3..8c5958b563 100644 --- a/lib/sqlalchemy/dialects/mysql/expression.py +++ b/lib/sqlalchemy/dialects/mysql/expression.py @@ -7,9 +7,8 @@ from sqlalchemy.sql import operators from sqlalchemy.util import immutabledict -def property_enables_flag(flag_name): +def enables_flag(flag_name): def wrapper(target): - @property @wraps(target) def inner(self): update = {flag_name: True} @@ -41,7 +40,7 @@ class match_(elements.ColumnElement): ) stmt = select(users_table)\ - .where(match_expr.in_boolean_mode)\ + .where(match_expr.in_boolean_mode())\ .order_by(desc(match_expr)) Would produce SQL resembling:: @@ -61,8 +60,9 @@ class match_(elements.ColumnElement): :param: against typically scalar expression to be coerced into a ``str`` - :param: flags optional ``dict``. Use properties ``in_boolean_mode``, - ``in_natural_language_mode`` and ``with_query_expansion`` to control it:: + :param: flags optional ``sqlalchemy.util.immutabledict``. Use methods + `in_boolean_mode``, ``in_natural_language_mode`` and + ``with_query_expansion`` to control it:: match_expr = match_( users_table.c.firstname, @@ -74,22 +74,22 @@ class match_(elements.ColumnElement): # MATCH(firstname, lastname) AGAINST (:param_1) - print(match_expr.in_boolean_mode) + print(match_expr.in_boolean_mode()) # MATCH(firstname, lastname) AGAINST (:param_1 IN BOOLEAN MODE) - print(match_expr.in_natural_language_mode.with_query_expansion) + print(match_expr.in_natural_language_mode().with_query_expansion()) # MATCH(firstname, lastname) AGAINST # (:param_1 IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION) - :property: ``in_boolean_mode`` returns new ``match_`` object with + :meth: ``in_boolean_mode`` returns new ``match_`` object with set to ``True`` the ``mysql_boolean_mode`` flag - :property: ``in_natural_language_mode`` returns new ``match_`` object with + :meth: ``in_natural_language_mode`` returns new ``match_`` object with set to ``True`` the ``mysql_natural_language`` flag - :property: ``with_query_expansion`` returns new ``match_`` object with + :meth: ``with_query_expansion`` returns new ``match_`` object with set to ``True`` the ``mysql_query_expansion`` flag .. versionadded:: 1.4.20 @@ -136,15 +136,15 @@ class match_(elements.ColumnElement): self.against = against self.flags = kwargs.get("flags", self.default_flags) - @property_enables_flag("mysql_boolean_mode") + @enables_flag("mysql_boolean_mode") def in_boolean_mode(self): pass - @property_enables_flag("mysql_natural_language") + @enables_flag("mysql_natural_language") def in_natural_language_mode(self): pass - @property_enables_flag("mysql_query_expansion") + @enables_flag("mysql_query_expansion") def with_query_expansion(self): pass diff --git a/test/dialect/mysql/test_compiler.py b/test/dialect/mysql/test_compiler.py index fc98b9fae5..9e7eb0acf3 100644 --- a/test/dialect/mysql/test_compiler.py +++ b/test/dialect/mysql/test_compiler.py @@ -1333,28 +1333,28 @@ class MatchExpressionTest(fixtures.TestBase, AssertsCompiledSQL): ) self.assert_compile( - expr.in_boolean_mode, + expr.in_boolean_mode(), "MATCH (user.firstname, user.lastname) AGAINST " "(%s IN BOOLEAN MODE)", dialect=self.__dialect__, ) self.assert_compile( - expr.in_natural_language_mode, + expr.in_natural_language_mode(), "MATCH (user.firstname, user.lastname) AGAINST " "(%s IN NATURAL LANGUAGE MODE)", dialect=self.__dialect__, ) self.assert_compile( - expr.with_query_expansion, + expr.with_query_expansion(), "MATCH (user.firstname, user.lastname) AGAINST " "(%s WITH QUERY EXPANSION)", dialect=self.__dialect__, ) self.assert_compile( - expr.in_natural_language_mode.with_query_expansion, + expr.in_natural_language_mode().with_query_expansion(), "MATCH (user.firstname, user.lastname) AGAINST " "(%s IN NATURAL LANGUAGE MODE WITH QUERY EXPANSION)", dialect=self.__dialect__, @@ -1383,22 +1383,22 @@ class MatchExpressionTest(fixtures.TestBase, AssertsCompiledSQL): assert_raises_message( exc.CompileError, msg % (True, False, True), - expr.in_boolean_mode.with_query_expansion.compile, + expr.in_boolean_mode().with_query_expansion().compile, dialect=self.__dialect__, ) assert_raises_message( exc.CompileError, msg % (True, True, False), - expr.in_boolean_mode.in_natural_language_mode.compile, + expr.in_boolean_mode().in_natural_language_mode().compile, dialect=self.__dialect__, ) # fmt: off callback = expr\ - .in_boolean_mode\ - .in_natural_language_mode\ - .with_query_expansion\ + .in_boolean_mode()\ + .in_natural_language_mode()\ + .with_query_expansion()\ .compile # fmt: on