]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Fix black warnings
authorAnton Kovalevich <kai3341@gmail.com>
Sun, 6 Jun 2021 14:02:28 +0000 (17:02 +0300)
committerAnton Kovalevich <kai3341@gmail.com>
Sun, 6 Jun 2021 14:02:28 +0000 (17:02 +0300)
lib/sqlalchemy/dialects/mysql/base.py
lib/sqlalchemy/dialects/mysql/expression.py
test/dialect/mysql/test_compiler.py

index 426597d72ef6e799399259bdcb2da73ea66a3f68..68ecd2bb25d0fbcb6c4234900cf2093ccd1feac7 100644 (file)
@@ -1584,19 +1584,21 @@ class MySQLCompiler(compiler.SQLCompiler):
             self.process(binary.right, **kw),
         )
 
-    match_valid_flag_combinations = frozenset((
-        # (boolean_mode, natural_language, query_expansion)
-        (False, False, False),
-        (True, False, False),
-        (False, True, False),
-        (False, False, True),
-        (False, True, True),
-    ))
+    match_valid_flag_combinations = frozenset(
+        (
+            # (boolean_mode, natural_language, query_expansion)
+            (False, False, False),
+            (True, False, False),
+            (False, True, False),
+            (False, False, True),
+            (False, True, True),
+        )
+    )
 
     match_flag_expressions = (
-        'IN BOOLEAN MODE',
-        'IN NATURAL LANGUAGE MODE',
-        'WITH QUERY EXPANSION',
+        "IN BOOLEAN MODE",
+        "IN NATURAL LANGUAGE MODE",
+        "WITH QUERY EXPANSION",
     )
 
     def visit_match_op_binary(self, binary, operator, **kw):
@@ -1607,17 +1609,17 @@ class MySQLCompiler(compiler.SQLCompiler):
 
         modifiers = binary.modifiers
 
-        boolean_mode = modifiers.get('mysql_boolean_mode', True)
-        natural_language = modifiers.get('mysql_natural_language', False)
-        query_expansion = modifiers.get('mysql_query_expansion', False)
+        boolean_mode = modifiers.get("mysql_boolean_mode", True)
+        natural_language = modifiers.get("mysql_natural_language", False)
+        query_expansion = modifiers.get("mysql_query_expansion", False)
 
         flag_combination = (boolean_mode, natural_language, query_expansion)
 
         if flag_combination not in self.match_valid_flag_combinations:
             flags = (
-                'mysql_boolean_mode=%s' % boolean_mode,
-                'mysql_natural_language=%s' % natural_language,
-                'mysql_query_expansion=%s' % query_expansion,
+                "mysql_boolean_mode=%s" % boolean_mode,
+                "mysql_natural_language=%s" % natural_language,
+                "mysql_query_expansion=%s" % query_expansion,
             )
 
             flags = ", ".join(flags)
@@ -1627,7 +1629,7 @@ class MySQLCompiler(compiler.SQLCompiler):
             )
 
         match_clause = binary.left
-        mysql_additional_cols = modifiers.get('mysql_additional_cols')
+        mysql_additional_cols = modifiers.get("mysql_additional_cols")
 
         if mysql_additional_cols:
             match_clause = [match_clause]
@@ -1652,7 +1654,7 @@ class MySQLCompiler(compiler.SQLCompiler):
             against_clause = [against_clause]
             against_clause.extend(flag_expressions)
 
-            against_clause = ' '.join(against_clause)
+            against_clause = " ".join(against_clause)
 
         return "MATCH (%s) AGAINST (%s)" % (match_clause, against_clause)
 
index 8134c5648d4f1acbb07bfe487c07a61a8cba8337..287f6f0718ebd33c40065898d5023817e9ecda74 100644 (file)
@@ -2,8 +2,8 @@ from functools import wraps
 
 from sqlalchemy import exc
 from sqlalchemy.ext.compiler import compiles
-from sqlalchemy.sql import operators
 from sqlalchemy.sql import elements
+from sqlalchemy.sql import operators
 
 
 def property_enables_flag(flag_name):
@@ -21,6 +21,7 @@ def property_enables_flag(flag_name):
             )
 
         return inner
+
     return wrapper
 
 
@@ -60,7 +61,7 @@ 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:
+     ``in_natural_language_mode`` and ``with_query_expansion`` to control it::
 
         match_expr = match_(
             users_table.c.firstname,
@@ -90,7 +91,7 @@ class match_(elements.ColumnElement):
     :property: ``with_query_expansion`` returns new ``match_`` object with
      set to ``True`` the ``mysql_query_expansion`` flag
 
-     .. versionadded:: 1.4.4
+    .. versionadded:: 1.4.20
 
     .. seealso::
 
@@ -99,9 +100,9 @@ class match_(elements.ColumnElement):
     """
 
     default_flags = {
-        'mysql_boolean_mode': False,
-        'mysql_natural_language': False,
-        'mysql_query_expansion': False,
+        "mysql_boolean_mode": False,
+        "mysql_natural_language": False,
+        "mysql_query_expansion": False,
     }
 
     def __init__(self, *clauselist, **kwargs):
@@ -118,8 +119,8 @@ class match_(elements.ColumnElement):
             clause.group = False
             self.clause = clause
 
-        against = kwargs.get('against')
-        flags = kwargs.get('flags')
+        against = kwargs.get("against")
+        flags = kwargs.get("flags")
 
         if against is None:
             raise exc.CompileError("Can not match without against")
@@ -127,24 +128,21 @@ class match_(elements.ColumnElement):
         self.against = against
         self.flags = flags or self.default_flags.copy()
 
-    @property_enables_flag('mysql_boolean_mode')
+    @property_enables_flag("mysql_boolean_mode")
     def in_boolean_mode(self):
         pass
 
-    @property_enables_flag('mysql_natural_language')
+    @property_enables_flag("mysql_natural_language")
     def in_natural_language_mode(self):
         pass
 
-    @property_enables_flag('mysql_query_expansion')
+    @property_enables_flag("mysql_query_expansion")
     def with_query_expansion(self):
         pass
 
 
 @compiles(match_, "mysql")
 def visit_match(element, compiler, **kw):
-    target = element.clause.match(
-        element.against,
-        **element.flags
-    )
+    target = element.clause.match(element.against, **element.flags)
 
     return compiler.process(target, **kw)
index 9adabf42bc1137fcc715f4aae8cc56492cc4e6fd..fc98b9fae5417ddd1c55e5373689c74c62906bca 100644 (file)
@@ -477,10 +477,12 @@ class CompileTest(fixtures.TestBase, AssertsCompiledSQL):
         matchtable = table("matchtable", column("title", String))
         title = matchtable.c.title
 
-        msg = "Flag combination does not make sence: " \
-            "mysql_boolean_mode=%s, " \
-            "mysql_natural_language=%s, " \
+        msg = (
+            "Flag combination does not make sence: "
+            "mysql_boolean_mode=%s, "
+            "mysql_natural_language=%s, "
             "mysql_query_expansion=%s"
+        )
 
         assert_raises_message(
             exc.CompileError,
@@ -1371,31 +1373,38 @@ class MatchExpressionTest(fixtures.TestBase, AssertsCompiledSQL):
 
         expr = match_(firstname, lastname, against="John Connor")
 
-        msg = "Flag combination does not make sence: " \
-            "mysql_boolean_mode=%s, " \
-            "mysql_natural_language=%s, " \
+        msg = (
+            "Flag combination does not make sence: "
+            "mysql_boolean_mode=%s, "
+            "mysql_natural_language=%s, "
             "mysql_query_expansion=%s"
+        )
 
         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\
+            .compile
+        # fmt: on
+
         assert_raises_message(
             exc.CompileError,
             msg % (True, True, True),
-            expr.in_boolean_mode.in_natural_language_mode.with_query_expansion
-            .compile,
+            callback,
             dialect=self.__dialect__,
         )