From: Yuval Dinari <> Date: Tue, 16 Jul 2019 08:16:40 +0000 (+0300) Subject: PEP8 changes created automatically by autopep8 tool X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cd068fca140c86a4ba80121a4e2778730b8c3f1b;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git PEP8 changes created automatically by autopep8 tool Fixes: #4623 --- diff --git a/lib/sqlalchemy/dialects/postgresql/psycopg2.py b/lib/sqlalchemy/dialects/postgresql/psycopg2.py index b2d09694ca..904995593e 100644 --- a/lib/sqlalchemy/dialects/postgresql/psycopg2.py +++ b/lib/sqlalchemy/dialects/postgresql/psycopg2.py @@ -562,17 +562,33 @@ class PGCompiler_psycopg2(PGCompiler): self.multiple_rows = inline self.execute_values_insert_template = None self.execute_values_page_size = 2000 - super(PGCompiler_psycopg2, PGCompiler_psycopg2).__init__(self, dialect, statement, column_keys, inline, **kwargs) - - # Override SQLCompiler.generate_values_placeholders_str- enable use of psycopg2 execute_values() - def generate_values_placeholders_str(self, crud_params, returning_clause_exists): + super( + PGCompiler_psycopg2, + PGCompiler_psycopg2).__init__( + self, + dialect, + statement, + column_keys, + inline, + **kwargs) + + # Override SQLCompiler.generate_values_placeholders_str - enable use of + # psycopg2 execute_values() + def generate_values_placeholders_str( + self, crud_params, returning_clause_exists): # Currently not using psycopg2.execute_values() when there's a returning clause; need to add support # for receiving multiple return values from insert query if self.multiple_rows and not returning_clause_exists and self.dialect.psycopg2_batch_mode == 'execute_values': - self.execute_values_insert_template = "(" + ", ".join([c[1] for c in crud_params]) + ")" + self.execute_values_insert_template = "(" + \ + ", ".join([c[1] for c in crud_params]) + ")" return " VALUES %s" else: - return super(PGCompiler_psycopg2, PGCompiler_psycopg2).generate_values_placeholders_str(self, crud_params, returning_clause_exists) + return super( + PGCompiler_psycopg2, + PGCompiler_psycopg2).generate_values_placeholders_str( + self, + crud_params, + returning_clause_exists) class PGIdentifierPreparer_psycopg2(PGIdentifierPreparer): @@ -789,7 +805,11 @@ class PGDialect_psycopg2(PGDialect): def do_executemany(self, cursor, statement, parameters, context=None): if self.psycopg2_batch_mode == 'execute_values' and context and context.compiled.execute_values_insert_template: self._psycopg2_extras().execute_values( - cursor, statement, parameters, template=context.compiled.execute_values_insert_template, page_size=context.compiled.execute_values_page_size) + cursor, + statement, + parameters, + template=context.compiled.execute_values_insert_template, + page_size=context.compiled.execute_values_page_size) # Support True for backward compatibility elif self.psycopg2_batch_mode in ('execute_batch', True): self._psycopg2_extras().execute_batch(cursor, statement, parameters) diff --git a/lib/sqlalchemy/sql/compiler.py b/lib/sqlalchemy/sql/compiler.py index 7515ef1d79..473a839f8b 100644 --- a/lib/sqlalchemy/sql/compiler.py +++ b/lib/sqlalchemy/sql/compiler.py @@ -2499,7 +2499,8 @@ class SQLCompiler(Compiled): ) ) else: - text += self.generate_values_placeholders_str(crud_params, returning_clause is not None) + text += self.generate_values_placeholders_str( + crud_params, returning_clause is not None) if insert_stmt._post_values_clause is not None: post_values_clause = self.process( @@ -2518,7 +2519,8 @@ class SQLCompiler(Compiled): return text - def generate_values_placeholders_str(self, crud_params, returning_clause_exists): + def generate_values_placeholders_str( + self, crud_params, returning_clause_exists): """ Generate the VALUES place holder string Should be overridden in classes that need a different implementation than the default diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py index 7682213c71..13f1c0e54f 100644 --- a/test/dialect/postgresql/test_dialect.py +++ b/test/dialect/postgresql/test_dialect.py @@ -242,7 +242,8 @@ class ExecuteValuesInsertsTest(fixtures.TablesTest): def setup(self): super(ExecuteValuesInsertsTest, self).setup() - self.engine = engines.testing_engine(options={"use_batch_mode": "execute_values"}) + self.engine = engines.testing_engine( + options={"use_batch_mode": "execute_values"}) def teardown(self): self.engine.dispose() @@ -295,7 +296,8 @@ class ExecuteValuesInsertsTest(fixtures.TablesTest): def test_correct_arguments(self): def execute_values(cur, sql, argslist, template=None, page_size=100): assert sql == "INSERT INTO data (x, y) VALUES %s" - assert argslist == ({'x': 'x1', 'y': 'y1'}, {'x': 'x2', 'y': 'y2'}, {'x': 'x3', 'y': 'y3'}) + assert argslist == ({'x': 'x1', 'y': 'y1'}, { + 'x': 'x2', 'y': 'y2'}, {'x': 'x3', 'y': 'y3'}) assert template == "(%(x)s, %(y)s)" assert page_size == 2000