Skip to content

Commit 1a179da

Browse files
authored
Upgrade black (#1373)
* upgrade black * run black on codebase
1 parent d8b0721 commit 1a179da

File tree

7 files changed

+52
-106
lines changed

7 files changed

+52
-106
lines changed

piccolo/columns/m2m.py

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,59 +93,51 @@ def get_select_string(
9393
if engine_type in ("postgres", "cockroach"):
9494
if self.as_list:
9595
column_name = self.columns[0]._meta.db_column_name
96-
return QueryString(
97-
f"""
96+
return QueryString(f"""
9897
ARRAY(
9998
SELECT
10099
"inner_{table_2_name}"."{column_name}"
101100
FROM {inner_select}
102101
) AS "{m2m_relationship_name}"
103-
"""
104-
)
102+
""")
105103
elif not self.serialisation_safe:
106104
column_name = table_2_pk_name
107-
return QueryString(
108-
f"""
105+
return QueryString(f"""
109106
ARRAY(
110107
SELECT
111108
"inner_{table_2_name}"."{column_name}"
112109
FROM {inner_select}
113110
) AS "{m2m_relationship_name}"
114-
"""
115-
)
111+
""")
116112
else:
117113
column_names = ", ".join(
118114
f'"inner_{table_2_name}"."{column._meta.db_column_name}"'
119115
for column in self.columns
120116
)
121-
return QueryString(
122-
f"""
117+
return QueryString(f"""
123118
(
124119
SELECT JSON_AGG({m2m_relationship_name}_results)
125120
FROM (
126121
SELECT {column_names} FROM {inner_select}
127122
) AS "{m2m_relationship_name}_results"
128123
) AS "{m2m_relationship_name}"
129-
"""
130-
)
124+
""")
131125
elif engine_type == "sqlite":
132126
if len(self.columns) > 1 or not self.serialisation_safe:
133127
column_name = table_2_pk_name
134128
else:
135129
assert len(self.columns) > 0
136130
column_name = self.columns[0]._meta.db_column_name
137131

138-
return QueryString(
139-
f"""
132+
return QueryString(f"""
140133
(
141134
SELECT group_concat(
142135
"inner_{table_2_name}"."{column_name}"
143136
)
144137
FROM {inner_select}
145138
)
146139
AS "{m2m_relationship_name} [M2M]"
147-
"""
148-
)
140+
""")
149141
else:
150142
raise ValueError(f"{engine_type} is an unrecognised engine type")
151143

piccolo/utils/list.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def flatten(
8-
items: Sequence[Union[ElementType, list[ElementType]]]
8+
items: Sequence[Union[ElementType, list[ElementType]]],
99
) -> list[ElementType]:
1010
"""
1111
Takes a sequence of elements, and flattens it out. For example::

requirements/dev-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
black==24.3.0
1+
black==26.3.1
22
ipdb==0.13.9
33
ipython>=7.31.1
44
flake8==6.1.0

tests/apps/migrations/auto/integration/test_migrations.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,8 +1089,7 @@ def test_target_column(self):
10891089
self.assertTrue(table_class.table_exists().run_sync())
10901090

10911091
# Make sure the constraint was created correctly.
1092-
response = self.run_sync(
1093-
"""
1092+
response = self.run_sync("""
10941093
SELECT EXISTS(
10951094
SELECT 1
10961095
FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE CCU
@@ -1101,8 +1100,7 @@ def test_target_column(self):
11011100
AND CCU.TABLE_NAME = 'table_a'
11021101
AND CCU.COLUMN_NAME = 'name'
11031102
)
1104-
"""
1105-
)
1103+
""")
11061104
self.assertTrue(response[0]["exists"])
11071105

11081106

tests/base.py

Lines changed: 36 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -248,98 +248,75 @@ def create_tables(self):
248248
assert ENGINE is not None
249249

250250
if ENGINE.engine_type in ("postgres", "cockroach"):
251-
self.run_sync(
252-
"""
251+
self.run_sync("""
253252
CREATE TABLE manager (
254253
id SERIAL PRIMARY KEY,
255254
name VARCHAR(50)
256-
);"""
257-
)
258-
self.run_sync(
259-
"""
255+
);""")
256+
self.run_sync("""
260257
CREATE TABLE band (
261258
id SERIAL PRIMARY KEY,
262259
name VARCHAR(50),
263260
manager INTEGER REFERENCES manager,
264261
popularity SMALLINT
265-
);"""
266-
)
267-
self.run_sync(
268-
"""
262+
);""")
263+
self.run_sync("""
269264
CREATE TABLE ticket (
270265
id SERIAL PRIMARY KEY,
271266
price NUMERIC(5,2)
272-
);"""
273-
)
274-
self.run_sync(
275-
"""
267+
);""")
268+
self.run_sync("""
276269
CREATE TABLE poster (
277270
id SERIAL PRIMARY KEY,
278271
content TEXT
279-
);"""
280-
)
281-
self.run_sync(
282-
"""
272+
);""")
273+
self.run_sync("""
283274
CREATE TABLE shirt (
284275
id SERIAL PRIMARY KEY,
285276
size VARCHAR(1)
286-
);"""
287-
)
277+
);""")
288278
elif ENGINE.engine_type == "sqlite":
289-
self.run_sync(
290-
"""
279+
self.run_sync("""
291280
CREATE TABLE manager (
292281
id INTEGER PRIMARY KEY,
293282
name VARCHAR(50)
294-
);"""
295-
)
296-
self.run_sync(
297-
"""
283+
);""")
284+
self.run_sync("""
298285
CREATE TABLE band (
299286
id INTEGER PRIMARY KEY,
300287
name VARCHAR(50),
301288
manager INTEGER REFERENCES manager,
302289
popularity SMALLINT
303-
);"""
304-
)
305-
self.run_sync(
306-
"""
290+
);""")
291+
self.run_sync("""
307292
CREATE TABLE ticket (
308293
id SERIAL PRIMARY KEY,
309294
price NUMERIC(5,2)
310-
);"""
311-
)
312-
self.run_sync(
313-
"""
295+
);""")
296+
self.run_sync("""
314297
CREATE TABLE poster (
315298
id SERIAL PRIMARY KEY,
316299
content TEXT
317-
);"""
318-
)
319-
self.run_sync(
320-
"""
300+
);""")
301+
self.run_sync("""
321302
CREATE TABLE shirt (
322303
id SERIAL PRIMARY KEY,
323304
size VARCHAR(1)
324-
);"""
325-
)
305+
);""")
326306
else:
327307
raise Exception("Unrecognised engine")
328308

329309
def insert_row(self):
330310
assert ENGINE is not None
331311

332312
if ENGINE.engine_type == "cockroach":
333-
id = self.run_sync(
334-
"""
313+
id = self.run_sync("""
335314
INSERT INTO manager (
336315
name
337316
) VALUES (
338317
'Guido'
339-
) RETURNING id;"""
340-
)
341-
self.run_sync(
342-
f"""
318+
) RETURNING id;""")
319+
self.run_sync(f"""
343320
INSERT INTO band (
344321
name,
345322
manager,
@@ -348,19 +325,15 @@ def insert_row(self):
348325
'Pythonistas',
349326
{id[0]["id"]},
350327
1000
351-
);"""
352-
)
328+
);""")
353329
else:
354-
self.run_sync(
355-
"""
330+
self.run_sync("""
356331
INSERT INTO manager (
357332
name
358333
) VALUES (
359334
'Guido'
360-
);"""
361-
)
362-
self.run_sync(
363-
"""
335+
);""")
336+
self.run_sync("""
364337
INSERT INTO band (
365338
name,
366339
manager,
@@ -369,15 +342,13 @@ def insert_row(self):
369342
'Pythonistas',
370343
1,
371344
1000
372-
);"""
373-
)
345+
);""")
374346

375347
def insert_rows(self):
376348
assert ENGINE is not None
377349

378350
if ENGINE.engine_type == "cockroach":
379-
id = self.run_sync(
380-
"""
351+
id = self.run_sync("""
381352
INSERT INTO manager (
382353
name
383354
) VALUES (
@@ -386,10 +357,8 @@ def insert_rows(self):
386357
'Graydon'
387358
),(
388359
'Mads'
389-
) RETURNING id;"""
390-
)
391-
self.run_sync(
392-
f"""
360+
) RETURNING id;""")
361+
self.run_sync(f"""
393362
INSERT INTO band (
394363
name,
395364
manager,
@@ -406,11 +375,9 @@ def insert_rows(self):
406375
'CSharps',
407376
{id[2]["id"]},
408377
10
409-
);"""
410-
)
378+
);""")
411379
else:
412-
self.run_sync(
413-
"""
380+
self.run_sync("""
414381
INSERT INTO manager (
415382
name
416383
) VALUES (
@@ -419,10 +386,8 @@ def insert_rows(self):
419386
'Graydon'
420387
),(
421388
'Mads'
422-
);"""
423-
)
424-
self.run_sync(
425-
"""
389+
);""")
390+
self.run_sync("""
426391
INSERT INTO band (
427392
name,
428393
manager,
@@ -439,8 +404,7 @@ def insert_rows(self):
439404
'CSharps',
440405
3,
441406
10
442-
);"""
443-
)
407+
);""")
444408

445409
def insert_many_rows(self, row_count=10000):
446410
"""

tests/table/test_insert.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,18 +253,12 @@ def test_target_string(self):
253253
"""
254254
Band = self.Band
255255

256-
constraint_name = [
257-
i["constraint_name"]
258-
for i in Band.raw(
259-
"""
256+
constraint_name = [i["constraint_name"] for i in Band.raw("""
260257
SELECT constraint_name
261258
FROM information_schema.constraint_column_usage
262259
WHERE column_name = 'name'
263260
AND table_name = 'band';
264-
"""
265-
).run_sync()
266-
if i["constraint_name"].endswith("_key")
267-
][0]
261+
""").run_sync() if i["constraint_name"].endswith("_key")][0]
268262

269263
query = Band.insert(Band(name=self.band.name)).on_conflict(
270264
target=constraint_name,

tests/table/test_select.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -688,8 +688,7 @@ def test_count_column_group_by(self):
688688
"""
689689
self.insert_rows()
690690
self.insert_rows()
691-
self.run_sync(
692-
"""
691+
self.run_sync("""
693692
INSERT INTO band (
694693
name,
695694
manager,
@@ -698,8 +697,7 @@ def test_count_column_group_by(self):
698697
'SomeBand',
699698
null,
700699
1000
701-
);"""
702-
)
700+
);""")
703701

704702
response = (
705703
Band.select(Band.manager.name, Count(Band.manager))

0 commit comments

Comments
 (0)