From f8a21aa6262d1bcc9ff0d11a2616e41fba97a47a Mon Sep 17 00:00:00 2001 From: Alessio Bogon Date: Sun, 15 Sep 2019 12:18:53 +0200 Subject: [PATCH] Fix pep8 issues --- lib/sqlalchemy/ext/linter.py | 9 +++++---- test/ext/test_linter.py | 29 ++++++++++++++++++++++------- 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/lib/sqlalchemy/ext/linter.py b/lib/sqlalchemy/ext/linter.py index 3ffa83d9bb..29d4dcb457 100644 --- a/lib/sqlalchemy/ext/linter.py +++ b/lib/sqlalchemy/ext/linter.py @@ -2,7 +2,6 @@ import collections import itertools from sqlalchemy import util - from sqlalchemy.sql import visitors from sqlalchemy.sql.expression import Select @@ -17,8 +16,9 @@ def before_execute_hook(conn, clauseelement, multiparams, params): def find_unmatching_froms(query, start_with=None): - # type: (Select, Optional[FromClause]) -> Tuple[Set[FromClause], FromClause] - # TODO: It would be nicer to use OrderedSet, but it seems to not be too much optimize, so let's skip for now + # type: (Select, Optional[FromClause]) -> Tuple[Set[FromClause], FromClause] # noqa + # TODO: It would be nicer to use OrderedSet, but it seems to not + # be too much optimized, so let's skip for now froms = set(query.froms) if not froms: return None, None @@ -97,7 +97,8 @@ def warn_for_unmatching_froms(query): # type: (Select) -> None froms, start_with = find_unmatching_froms(query) if froms: - template = '''Query\n{query}\nhas FROM elements:\n{froms}\nthat are not joined up to FROM element\n{start}''' + template = 'Query\n{query}\nhas FROM elements:\n{froms}\nthat ' \ + 'are not joined up to FROM element\n{start}''' indent = ' ' froms_str = '\n'.join('* {elem}'.format(elem=from_) for from_ in froms) message = template.format( diff --git a/test/ext/test_linter.py b/test/ext/test_linter.py index b8bc76f892..e962b1fcc8 100644 --- a/test/ext/test_linter.py +++ b/test/ext/test_linter.py @@ -1,9 +1,9 @@ -from sqlalchemy import select, Integer, event, testing +from sqlalchemy import event, Integer, select, testing from sqlalchemy.ext import linter from sqlalchemy.ext.linter import find_unmatching_froms -from sqlalchemy.testing import fixtures, expect_warnings -from sqlalchemy.testing.schema import Table, Column +from sqlalchemy.testing import expect_warnings, fixtures from sqlalchemy.testing.mock import patch +from sqlalchemy.testing.schema import Column, Table class TestFindUnmatchingFroms(fixtures.TablesTest): @@ -105,7 +105,11 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): assert not froms def test_disconnected_subquery(self): - subq = select([self.a]).where(self.a.c.col_a == self.b.c.col_b).subquery() + subq = ( + select([self.a]) + .where(self.a.c.col_a == self.b.c.col_b) + .subquery() + ) stmt = select([self.c]).select_from(subq) froms, start = find_unmatching_froms(stmt, self.c) @@ -117,8 +121,16 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): assert froms == {self.c} def test_now_connect_it(self): - subq = select([self.a]).where(self.a.c.col_a == self.b.c.col_b).subquery() - stmt = select([self.c]).select_from(subq).where(self.c.c.col_c == subq.c.col_a) + subq = ( + select([self.a]) + .where(self.a.c.col_a == self.b.c.col_b) + .subquery() + ) + stmt = ( + select([self.c]) + .select_from(subq) + .where(self.c.c.col_c == subq.c.col_a) + ) froms, start = find_unmatching_froms(stmt) assert not froms @@ -131,7 +143,10 @@ class TestFindUnmatchingFroms(fixtures.TablesTest): query = ( select([self.a]) .select_from( - self.a.join(self.b.join(self.c, self.b.c.col_b == self.c.c.col_c), self.a.c.col_a == self.b.c.col_b) + self.a.join( + self.b.join(self.c, self.b.c.col_b == self.c.c.col_c), + self.a.c.col_a == self.b.c.col_b, + ) ) ) froms, start = find_unmatching_froms(query) -- 2.47.2