From f0b73bb78f6d9c8a222b26fdf6ac12d39a8530fa Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Tue, 24 Mar 2026 12:30:10 +0000 Subject: [PATCH 1/2] upgrade black --- requirements/dev-requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/requirements/dev-requirements.txt b/requirements/dev-requirements.txt index 6807bf875..65c2d69f5 100644 --- a/requirements/dev-requirements.txt +++ b/requirements/dev-requirements.txt @@ -1,4 +1,4 @@ -black==24.3.0 +black==26.3.1 ipdb==0.13.9 ipython>=7.31.1 flake8==6.1.0 From 2cff5faf81c976389979aeb9f2a953edd2355931 Mon Sep 17 00:00:00 2001 From: Daniel Townsend Date: Tue, 24 Mar 2026 12:33:04 +0000 Subject: [PATCH 2/2] run black on codebase --- piccolo/columns/m2m.py | 24 ++-- piccolo/utils/list.py | 2 +- .../auto/integration/test_migrations.py | 6 +- tests/base.py | 108 ++++++------------ tests/table/test_insert.py | 10 +- tests/table/test_select.py | 6 +- 6 files changed, 51 insertions(+), 105 deletions(-) diff --git a/piccolo/columns/m2m.py b/piccolo/columns/m2m.py index b8d34d46b..a8a6e6451 100644 --- a/piccolo/columns/m2m.py +++ b/piccolo/columns/m2m.py @@ -93,41 +93,35 @@ def get_select_string( if engine_type in ("postgres", "cockroach"): if self.as_list: column_name = self.columns[0]._meta.db_column_name - return QueryString( - f""" + return QueryString(f""" ARRAY( SELECT "inner_{table_2_name}"."{column_name}" FROM {inner_select} ) AS "{m2m_relationship_name}" - """ - ) + """) elif not self.serialisation_safe: column_name = table_2_pk_name - return QueryString( - f""" + return QueryString(f""" ARRAY( SELECT "inner_{table_2_name}"."{column_name}" FROM {inner_select} ) AS "{m2m_relationship_name}" - """ - ) + """) else: column_names = ", ".join( f'"inner_{table_2_name}"."{column._meta.db_column_name}"' for column in self.columns ) - return QueryString( - f""" + return QueryString(f""" ( SELECT JSON_AGG({m2m_relationship_name}_results) FROM ( SELECT {column_names} FROM {inner_select} ) AS "{m2m_relationship_name}_results" ) AS "{m2m_relationship_name}" - """ - ) + """) elif engine_type == "sqlite": if len(self.columns) > 1 or not self.serialisation_safe: column_name = table_2_pk_name @@ -135,8 +129,7 @@ def get_select_string( assert len(self.columns) > 0 column_name = self.columns[0]._meta.db_column_name - return QueryString( - f""" + return QueryString(f""" ( SELECT group_concat( "inner_{table_2_name}"."{column_name}" @@ -144,8 +137,7 @@ def get_select_string( FROM {inner_select} ) AS "{m2m_relationship_name} [M2M]" - """ - ) + """) else: raise ValueError(f"{engine_type} is an unrecognised engine type") diff --git a/piccolo/utils/list.py b/piccolo/utils/list.py index 8ec6aa066..3c77d4ded 100644 --- a/piccolo/utils/list.py +++ b/piccolo/utils/list.py @@ -5,7 +5,7 @@ def flatten( - items: Sequence[Union[ElementType, list[ElementType]]] + items: Sequence[Union[ElementType, list[ElementType]]], ) -> list[ElementType]: """ Takes a sequence of elements, and flattens it out. For example:: diff --git a/tests/apps/migrations/auto/integration/test_migrations.py b/tests/apps/migrations/auto/integration/test_migrations.py index a065d9588..656976200 100644 --- a/tests/apps/migrations/auto/integration/test_migrations.py +++ b/tests/apps/migrations/auto/integration/test_migrations.py @@ -1089,8 +1089,7 @@ def test_target_column(self): self.assertTrue(table_class.table_exists().run_sync()) # Make sure the constraint was created correctly. - response = self.run_sync( - """ + response = self.run_sync(""" SELECT EXISTS( SELECT 1 FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CCU @@ -1101,8 +1100,7 @@ def test_target_column(self): AND CCU.TABLE_NAME = 'table_a' AND CCU.COLUMN_NAME = 'name' ) - """ - ) + """) self.assertTrue(response[0]["exists"]) diff --git a/tests/base.py b/tests/base.py index d56e0ed9b..ecb1bfd55 100644 --- a/tests/base.py +++ b/tests/base.py @@ -248,81 +248,61 @@ def create_tables(self): assert ENGINE is not None if ENGINE.engine_type in ("postgres", "cockroach"): - self.run_sync( - """ + self.run_sync(""" CREATE TABLE manager ( id SERIAL PRIMARY KEY, name VARCHAR(50) - );""" - ) - self.run_sync( - """ + );""") + self.run_sync(""" CREATE TABLE band ( id SERIAL PRIMARY KEY, name VARCHAR(50), manager INTEGER REFERENCES manager, popularity SMALLINT - );""" - ) - self.run_sync( - """ + );""") + self.run_sync(""" CREATE TABLE ticket ( id SERIAL PRIMARY KEY, price NUMERIC(5,2) - );""" - ) - self.run_sync( - """ + );""") + self.run_sync(""" CREATE TABLE poster ( id SERIAL PRIMARY KEY, content TEXT - );""" - ) - self.run_sync( - """ + );""") + self.run_sync(""" CREATE TABLE shirt ( id SERIAL PRIMARY KEY, size VARCHAR(1) - );""" - ) + );""") elif ENGINE.engine_type == "sqlite": - self.run_sync( - """ + self.run_sync(""" CREATE TABLE manager ( id INTEGER PRIMARY KEY, name VARCHAR(50) - );""" - ) - self.run_sync( - """ + );""") + self.run_sync(""" CREATE TABLE band ( id INTEGER PRIMARY KEY, name VARCHAR(50), manager INTEGER REFERENCES manager, popularity SMALLINT - );""" - ) - self.run_sync( - """ + );""") + self.run_sync(""" CREATE TABLE ticket ( id SERIAL PRIMARY KEY, price NUMERIC(5,2) - );""" - ) - self.run_sync( - """ + );""") + self.run_sync(""" CREATE TABLE poster ( id SERIAL PRIMARY KEY, content TEXT - );""" - ) - self.run_sync( - """ + );""") + self.run_sync(""" CREATE TABLE shirt ( id SERIAL PRIMARY KEY, size VARCHAR(1) - );""" - ) + );""") else: raise Exception("Unrecognised engine") @@ -330,16 +310,13 @@ def insert_row(self): assert ENGINE is not None if ENGINE.engine_type == "cockroach": - id = self.run_sync( - """ + id = self.run_sync(""" INSERT INTO manager ( name ) VALUES ( 'Guido' - ) RETURNING id;""" - ) - self.run_sync( - f""" + ) RETURNING id;""") + self.run_sync(f""" INSERT INTO band ( name, manager, @@ -348,19 +325,15 @@ def insert_row(self): 'Pythonistas', {id[0]["id"]}, 1000 - );""" - ) + );""") else: - self.run_sync( - """ + self.run_sync(""" INSERT INTO manager ( name ) VALUES ( 'Guido' - );""" - ) - self.run_sync( - """ + );""") + self.run_sync(""" INSERT INTO band ( name, manager, @@ -369,15 +342,13 @@ def insert_row(self): 'Pythonistas', 1, 1000 - );""" - ) + );""") def insert_rows(self): assert ENGINE is not None if ENGINE.engine_type == "cockroach": - id = self.run_sync( - """ + id = self.run_sync(""" INSERT INTO manager ( name ) VALUES ( @@ -386,10 +357,8 @@ def insert_rows(self): 'Graydon' ),( 'Mads' - ) RETURNING id;""" - ) - self.run_sync( - f""" + ) RETURNING id;""") + self.run_sync(f""" INSERT INTO band ( name, manager, @@ -406,11 +375,9 @@ def insert_rows(self): 'CSharps', {id[2]["id"]}, 10 - );""" - ) + );""") else: - self.run_sync( - """ + self.run_sync(""" INSERT INTO manager ( name ) VALUES ( @@ -419,10 +386,8 @@ def insert_rows(self): 'Graydon' ),( 'Mads' - );""" - ) - self.run_sync( - """ + );""") + self.run_sync(""" INSERT INTO band ( name, manager, @@ -439,8 +404,7 @@ def insert_rows(self): 'CSharps', 3, 10 - );""" - ) + );""") def insert_many_rows(self, row_count=10000): """ diff --git a/tests/table/test_insert.py b/tests/table/test_insert.py index 19c1b0acb..4970a2c7a 100644 --- a/tests/table/test_insert.py +++ b/tests/table/test_insert.py @@ -253,18 +253,12 @@ def test_target_string(self): """ Band = self.Band - constraint_name = [ - i["constraint_name"] - for i in Band.raw( - """ + constraint_name = [i["constraint_name"] for i in Band.raw(""" SELECT constraint_name FROM information_schema.constraint_column_usage WHERE column_name = 'name' AND table_name = 'band'; - """ - ).run_sync() - if i["constraint_name"].endswith("_key") - ][0] + """).run_sync() if i["constraint_name"].endswith("_key")][0] query = Band.insert(Band(name=self.band.name)).on_conflict( target=constraint_name, diff --git a/tests/table/test_select.py b/tests/table/test_select.py index 1feac507f..b0f468c3c 100644 --- a/tests/table/test_select.py +++ b/tests/table/test_select.py @@ -688,8 +688,7 @@ def test_count_column_group_by(self): """ self.insert_rows() self.insert_rows() - self.run_sync( - """ + self.run_sync(""" INSERT INTO band ( name, manager, @@ -698,8 +697,7 @@ def test_count_column_group_by(self): 'SomeBand', null, 1000 - );""" - ) + );""") response = ( Band.select(Band.manager.name, Count(Band.manager))