]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Change API: drop properties, use regular methods instead 6133/head
authorAnton Kovalevich <kai3341@gmail.com>
Fri, 18 Jun 2021 12:39:08 +0000 (15:39 +0300)
committerAnton Kovalevich <kai3341@gmail.com>
Fri, 18 Jun 2021 12:39:08 +0000 (15:39 +0300)
lib/sqlalchemy/dialects/mysql/expression.py
test/dialect/mysql/test_compiler.py

index 72718bacb3b5fedfef9e403fb05cda5d55c32f34..8c5958b5634c0ef4a713d4865594c5ed92725215 100644 (file)
@@ -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
 
index fc98b9fae5417ddd1c55e5373689c74c62906bca..9e7eb0acf3ca34d02ed23e11c0512e51cac3b86c 100644 (file)
@@ -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