From 07fda81b2ed22159c7848a954eea11fa5f5e0c00 Mon Sep 17 00:00:00 2001 From: Federico Caselli Date: Mon, 27 Jan 2020 16:51:05 -0500 Subject: [PATCH] Add pyproject - Added pyproject.toml with black arguments - Updated black version in precommit hook - Reformatted the code Fixes: #5100 Closes: #5103 Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/5103 Pull-request-sha: 795fd5f896be4a07a2b18e6525674b815ac17593 Change-Id: I14eedbaa51fb531cbf90fcefe6a1e07c8a565625 (cherry picked from commit f49a3fc02c03e39b3d34da9dfba4fe46d71c4aff) --- .pre-commit-config.yaml | 3 +-- lib/sqlalchemy/__init__.py | 2 +- lib/sqlalchemy/dialects/oracle/cx_oracle.py | 2 +- lib/sqlalchemy/dialects/postgresql/base.py | 2 +- lib/sqlalchemy/engine/result.py | 8 +++++--- pyproject.toml | 2 ++ test/dialect/postgresql/test_reflection.py | 8 ++++---- test/ext/test_baked.py | 14 ++++++++------ test/orm/test_bulk.py | 14 +++++++------- test/orm/test_cycles.py | 4 ++-- test/orm/test_lazy_relations.py | 2 +- test/orm/test_naturalpks.py | 4 ++-- test/orm/test_rel_fn.py | 4 ++-- test/orm/test_selectin_relations.py | 2 +- 14 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 pyproject.toml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e4427aa3a3..af06dcd795 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -2,10 +2,9 @@ # See https://pre-commit.com/hooks.html for more hooks repos: - repo: https://github.com/python/black/ - rev: 19.3b0 + rev: 19.10b0 hooks: - id: black - args: [-l 79] - repo: https://github.com/sqlalchemyorg/zimports/ rev: master diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py index f278f1ff3e..f4625b60f2 100644 --- a/lib/sqlalchemy/__init__.py +++ b/lib/sqlalchemy/__init__.py @@ -123,7 +123,7 @@ from .engine import create_engine # noqa nosort from .engine import engine_from_config # noqa nosort -__version__ = '1.3.14' +__version__ = "1.3.14" def __go(lcls): diff --git a/lib/sqlalchemy/dialects/oracle/cx_oracle.py b/lib/sqlalchemy/dialects/oracle/cx_oracle.py index 2367374778..19cc3c3dcc 100644 --- a/lib/sqlalchemy/dialects/oracle/cx_oracle.py +++ b/lib/sqlalchemy/dialects/oracle/cx_oracle.py @@ -1085,7 +1085,7 @@ class OracleDialect_cx_oracle(OracleDialect): return tuple(int(x) for x in connection.connection.version.split(".")) def is_disconnect(self, e, connection, cursor): - error, = e.args + (error,) = e.args if isinstance( e, (self.dbapi.InterfaceError, self.dbapi.DatabaseError) ) and "not connected" in str(e): diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 1252e7e692..8d33219c3f 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -3489,7 +3489,7 @@ class PGDialect(default.DefaultDialect): util.warn("Could not parse CHECK constraint text: %r" % src) sqltext = "" else: - sqltext = re.sub(r'^\((.+)\)$', r'\1', m.group(1)) + sqltext = re.sub(r"^\((.+)\)$", r"\1", m.group(1)) entry = {"name": name, "sqltext": sqltext} if m and m.group(2): entry["dialect_options"] = {"not_valid": True} diff --git a/lib/sqlalchemy/engine/result.py b/lib/sqlalchemy/engine/result.py index 5729c009aa..ec9c58b042 100644 --- a/lib/sqlalchemy/engine/result.py +++ b/lib/sqlalchemy/engine/result.py @@ -220,9 +220,11 @@ class ResultMetaData(object): self._orig_processors = None if context.result_column_struct: - result_columns, cols_are_ordered, textual_ordered = ( - context.result_column_struct - ) + ( + result_columns, + cols_are_ordered, + textual_ordered, + ) = context.result_column_struct num_ctx_cols = len(result_columns) else: result_columns = ( diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000000..a8f43fefdf --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,2 @@ +[tool.black] +line-length = 79 diff --git a/test/dialect/postgresql/test_reflection.py b/test/dialect/postgresql/test_reflection.py index 9452e8de81..86d0f3e38d 100644 --- a/test/dialect/postgresql/test_reflection.py +++ b/test/dialect/postgresql/test_reflection.py @@ -1541,10 +1541,10 @@ class ReflectionTest(fixtures.TestBase): RETURN x > 0; END;$BODY$; """ - sa.event.listen(meta, "before_create", - sa.DDL(udf_create)) - sa.event.listen(meta, "after_drop", - sa.DDL("DROP FUNCTION is_positive(integer)")) + sa.event.listen(meta, "before_create", sa.DDL(udf_create)) + sa.event.listen( + meta, "after_drop", sa.DDL("DROP FUNCTION is_positive(integer)") + ) Table( "pgsql_cc", diff --git a/test/ext/test_baked.py b/test/ext/test_baked.py index 0a9a3e3554..dc8eb8cc56 100644 --- a/test/ext/test_baked.py +++ b/test/ext/test_baked.py @@ -1436,15 +1436,17 @@ class LazyLoaderTest(testing.AssertsCompiledSQL, BakedTest): def test_simple_lazy_clause_no_race_on_generate(self): User, Address = self._o2m_fixture() - expr1, paramdict1 = ( - User.addresses.property._lazy_strategy._simple_lazy_clause - ) + ( + expr1, + paramdict1, + ) = User.addresses.property._lazy_strategy._simple_lazy_clause # delete the attr, as though a concurrent thread is also generating it del User.addresses.property._lazy_strategy._simple_lazy_clause - expr2, paramdict2 = ( - User.addresses.property._lazy_strategy._simple_lazy_clause - ) + ( + expr2, + paramdict2, + ) = User.addresses.property._lazy_strategy._simple_lazy_clause eq_(paramdict1, paramdict2) diff --git a/test/orm/test_bulk.py b/test/orm/test_bulk.py index 7d591e906c..79de19f684 100644 --- a/test/orm/test_bulk.py +++ b/test/orm/test_bulk.py @@ -81,7 +81,7 @@ class BulkInsertUpdateTest(BulkTest, _fixtures.FixtureTest): mapper(Order, o) def test_bulk_save_return_defaults(self): - User, = self.classes("User") + (User,) = self.classes("User") s = Session() objects = [User(name="u1"), User(name="u2"), User(name="u3")] @@ -104,7 +104,7 @@ class BulkInsertUpdateTest(BulkTest, _fixtures.FixtureTest): eq_(objects[0].__dict__["id"], 1) def test_bulk_save_mappings_preserve_order(self): - User, = self.classes("User") + (User,) = self.classes("User") s = Session() @@ -160,7 +160,7 @@ class BulkInsertUpdateTest(BulkTest, _fixtures.FixtureTest): ) def test_bulk_save_no_defaults(self): - User, = self.classes("User") + (User,) = self.classes("User") s = Session() objects = [User(name="u1"), User(name="u2"), User(name="u3")] @@ -178,7 +178,7 @@ class BulkInsertUpdateTest(BulkTest, _fixtures.FixtureTest): assert "id" not in objects[0].__dict__ def test_bulk_save_updated_include_unchanged(self): - User, = self.classes("User") + (User,) = self.classes("User") s = Session(expire_on_commit=False) objects = [User(name="u1"), User(name="u2"), User(name="u3")] @@ -204,7 +204,7 @@ class BulkInsertUpdateTest(BulkTest, _fixtures.FixtureTest): ) def test_bulk_update(self): - User, = self.classes("User") + (User,) = self.classes("User") s = Session(expire_on_commit=False) objects = [User(name="u1"), User(name="u2"), User(name="u3")] @@ -234,7 +234,7 @@ class BulkInsertUpdateTest(BulkTest, _fixtures.FixtureTest): ) def test_bulk_insert(self): - User, = self.classes("User") + (User,) = self.classes("User") s = Session() with self.sql_execution_asserter() as asserter: @@ -259,7 +259,7 @@ class BulkInsertUpdateTest(BulkTest, _fixtures.FixtureTest): ) def test_bulk_insert_render_nulls(self): - Order, = self.classes("Order") + (Order,) = self.classes("Order") s = Session() with self.sql_execution_asserter() as asserter: diff --git a/test/orm/test_cycles.py b/test/orm/test_cycles.py index 8cf4e4b5c6..7dd349a74a 100644 --- a/test/orm/test_cycles.py +++ b/test/orm/test_cycles.py @@ -1760,7 +1760,7 @@ class PostUpdateOnUpdateTest(fixtures.DeclarativeMappedTest): def test_update_defaults_refresh_flush_event_no_postupdate(self): # run the same test as test_update_defaults_refresh_flush_event # but don't actually use any postupdate functionality - A, = self.classes("A") + (A,) = self.classes("A") canary = mock.Mock() event.listen(A, "refresh_flush", canary.refresh_flush) @@ -1845,7 +1845,7 @@ class PostUpdateOnUpdateTest(fixtures.DeclarativeMappedTest): # run the same test as # test_update_defaults_dont_expire_on_delete_no_postupdate # but don't actually use any postupdate functionality - A, = self.classes("A") + (A,) = self.classes("A") canary = mock.Mock() event.listen(A, "refresh_flush", canary.refresh_flush) diff --git a/test/orm/test_lazy_relations.py b/test/orm/test_lazy_relations.py index 78680701e0..3566a5ca72 100644 --- a/test/orm/test_lazy_relations.py +++ b/test/orm/test_lazy_relations.py @@ -1417,7 +1417,7 @@ class O2MWOSideFixedTest(fixtures.MappedTest): self._fixture(False) City = self.classes.City sess = Session(testing.db) - c2, = sess.query(City).order_by(City.id).all() + (c2,) = sess.query(City).order_by(City.id).all() eq_([p.id for p in c2.people], []) diff --git a/test/orm/test_naturalpks.py b/test/orm/test_naturalpks.py index e9b9ac44f6..d7a4b0fab4 100644 --- a/test/orm/test_naturalpks.py +++ b/test/orm/test_naturalpks.py @@ -1612,7 +1612,7 @@ class JoinedInheritanceTest(fixtures.MappedTest): self._test_fk_threelevel(False) def _test_pk(self, passive_updates): - Engineer, = self.classes("Engineer") + (Engineer,) = self.classes("Engineer") self._mapping_fixture(False, passive_updates) sess = sa.orm.sessionmaker()() @@ -1685,7 +1685,7 @@ class JoinedInheritanceTest(fixtures.MappedTest): ) def _test_pk_threelevel(self, passive_updates): - Owner, = self.classes("Owner") + (Owner,) = self.classes("Owner") self._mapping_fixture(True, passive_updates) diff --git a/test/orm/test_rel_fn.py b/test/orm/test_rel_fn.py index 5e6ac53fe8..590cd48b41 100644 --- a/test/orm/test_rel_fn.py +++ b/test/orm/test_rel_fn.py @@ -807,7 +807,7 @@ class ColumnCollectionsTest( ) def test_determine_local_remote_pairs_o2m_composite_selfref_func_warning( - self + self, ): self._assert_non_simple_warning( self._join_fixture_o2m_composite_selfref_func @@ -823,7 +823,7 @@ class ColumnCollectionsTest( ) def test_determine_local_remote_pairs_o2m_composite_selfref_func_annotated( - self + self, ): joincond = self._join_fixture_o2m_composite_selfref_func_annotated() eq_( diff --git a/test/orm/test_selectin_relations.py b/test/orm/test_selectin_relations.py index 23f083ad21..021566dfec 100644 --- a/test/orm/test_selectin_relations.py +++ b/test/orm/test_selectin_relations.py @@ -3021,7 +3021,7 @@ class SingleInhSubclassTest( s.commit() def test_load(self): - EmployerUser, = self.classes("EmployerUser") + (EmployerUser,) = self.classes("EmployerUser") s = Session() q = s.query(EmployerUser) -- 2.47.2