From: Anton Kovalevich Date: Sun, 6 Jun 2021 14:02:28 +0000 (+0300) Subject: Fix black warnings X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5d8e669042b19e48f38c55962f972297762db36e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git Fix black warnings --- diff --git a/lib/sqlalchemy/dialects/mysql/base.py b/lib/sqlalchemy/dialects/mysql/base.py index 426597d72e..68ecd2bb25 100644 --- a/lib/sqlalchemy/dialects/mysql/base.py +++ b/lib/sqlalchemy/dialects/mysql/base.py @@ -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) diff --git a/lib/sqlalchemy/dialects/mysql/expression.py b/lib/sqlalchemy/dialects/mysql/expression.py index 8134c5648d..287f6f0718 100644 --- a/lib/sqlalchemy/dialects/mysql/expression.py +++ b/lib/sqlalchemy/dialects/mysql/expression.py @@ -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) diff --git a/test/dialect/mysql/test_compiler.py b/test/dialect/mysql/test_compiler.py index 9adabf42bc..fc98b9fae5 100644 --- a/test/dialect/mysql/test_compiler.py +++ b/test/dialect/mysql/test_compiler.py @@ -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__, )