Skip to content

Commit 40dce68

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent 3db0714 commit 40dce68

22 files changed

Lines changed: 79 additions & 121 deletions

File tree

api/actions.py

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@ def __change_rows(
10011001

10021002
sa_table = table_obj.get_oedb_table_proxy()._main_table.get_sa_table()
10031003

1004-
pks = [c for c in sa_table.columns if c.primary_key] # type:ignore
1004+
pks = [c for c in sa_table.columns if c.primary_key] # type: ignore
10051005

10061006
inserts = []
10071007
cursor = load_cursor_from_context(context)
@@ -1333,11 +1333,11 @@ def add_type(d, type):
13331333
engine = _get_engine()
13341334

13351335
artificial_connection = False
1336-
connection: DBAPIConnection = engine.raw_connection() # type:ignore TODO
1336+
connection: DBAPIConnection = engine.raw_connection() # type: ignore TODO
13371337

13381338
if cursor is None:
13391339
artificial_connection = True
1340-
cursor = cast(AbstractCursor, connection.cursor()) # type:ignore TODO
1340+
cursor = cast(AbstractCursor, connection.cursor()) # type: ignore TODO
13411341

13421342
try:
13431343
columns = list(describe_columns(table_obj).keys())
@@ -1545,7 +1545,7 @@ def set_table_metadata(table: str, metadata):
15451545
# ---------------------------------------
15461546

15471547
django_table_obj = Table.objects.get(name=table)
1548-
django_table_obj.oemetadata = metadata_obj # type:ignore
1548+
django_table_obj.oemetadata = metadata_obj # type: ignore
15491549
django_table_obj.save()
15501550

15511551
# ---------------------------------------
@@ -1570,8 +1570,7 @@ def get_single_table_size(table_obj: Table) -> dict | None:
15701570
Return size details for one table or None if not found.
15711571
"""
15721572

1573-
sql = text(
1574-
"""
1573+
sql = text("""
15751574
SELECT
15761575
:schema AS table_schema,
15771576
:table AS table_name,
@@ -1581,8 +1580,7 @@ def get_single_table_size(table_obj: Table) -> dict | None:
15811580
pg_size_pretty(pg_relation_size(format('%I.%I', :schema, :table))) AS table_pretty,
15821581
pg_size_pretty(pg_indexes_size(format('%I.%I', :schema, :table))) AS index_pretty,
15831582
pg_size_pretty(pg_total_relation_size(format('%I.%I', :schema, :table))) AS total_pretty
1584-
""" # noqa: E501
1585-
)
1583+
""") # noqa: E501
15861584

15871585
sess = _create_oedb_session()
15881586
try:
@@ -1605,8 +1603,7 @@ def list_table_sizes() -> list[dict]:
16051603
List table sizes
16061604
"""
16071605
oedb_schema = SCHEMA_DATA
1608-
sql = text(
1609-
f"""
1606+
sql = text(f"""
16101607
SELECT
16111608
table_schema,
16121609
table_name,
@@ -1618,8 +1615,7 @@ def list_table_sizes() -> list[dict]:
16181615
WHERE table_schema='{oedb_schema}'
16191616
AND table_type = 'BASE TABLE'
16201617
ORDER BY pg_total_relation_size(format('%I.%I', table_schema, table_name)) DESC
1621-
""" # noqa: E501
1622-
)
1618+
""") # noqa: E501
16231619

16241620
sess = _create_oedb_session()
16251621
try:
@@ -1637,14 +1633,12 @@ def list_table_sizes() -> list[dict]:
16371633

16381634

16391635
def table_has_row_with_id(table: Table, id: int | str, id_col: str = "id") -> bool:
1640-
query = text(
1641-
f"""
1636+
query = text(f"""
16421637
SELECT count(*)
16431638
FROM "{table.oedb_schema}"."{table.name}"
16441639
WHERE {id_col} = :id
16451640
;
1646-
"""
1647-
)
1641+
""")
16481642

16491643
engine = _get_engine()
16501644
with engine.connect() as conn:
@@ -1656,13 +1650,11 @@ def table_has_row_with_id(table: Table, id: int | str, id_col: str = "id") -> bo
16561650

16571651

16581652
def table_get_row_count(table: Table) -> int:
1659-
query = text(
1660-
f"""
1653+
query = text(f"""
16611654
SELECT count(*)
16621655
FROM "{table.oedb_schema}"."{table.name}"
16631656
;
1664-
"""
1665-
)
1657+
""")
16661658

16671659
engine = _get_engine()
16681660
with engine.connect() as conn:
@@ -1689,14 +1681,12 @@ def table_get_approx_row_count(table: Table, precise_below: int = 0) -> int:
16891681
# table name. but its validated by constraints
16901682
# on django table.name field
16911683

1692-
query = text(
1693-
f"""
1684+
query = text(f"""
16941685
SELECT reltuples::bigint AS approx_row_count
16951686
FROM pg_class
16961687
WHERE oid = '"{table.oedb_schema}"."{table.name}"'::regclass
16971688
;
1698-
"""
1699-
)
1689+
""")
17001690

17011691
with engine.connect() as conn:
17021692
resp = _execute(conn, query)
@@ -2118,7 +2108,7 @@ def _execute(
21182108
*args,
21192109
**kwargs,
21202110
) -> ResultProxy:
2121-
response = con.execute(sql, *args, **kwargs) # type:ignore
2111+
response = con.execute(sql, *args, **kwargs) # type: ignore
21222112
# Note: cast is only for type checking,
21232113
# should disappear once we migrate to sqlalchemy >= 1.4
21242114
response = cast(ResultProxy, response)

api/parser.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def get_column_definition_query(d: dict) -> Column:
128128

129129
if d.get("character_maximum_length"):
130130
max_len = int(d["character_maximum_length"])
131-
dt = dt(max_len) # type:ignore
131+
dt = dt(max_len) # type: ignore
132132

133133
_assert_valid_identifier_name(name)
134134
c = Column(name, dt, *args, **kwargs)
@@ -483,11 +483,11 @@ def _parse_from_item(d):
483483
on_clause = None
484484
if "on" in d:
485485
on_clause = parse_condition(d["on"])
486-
sa_table = left.join( # type:ignore
486+
sa_table = left.join( # type: ignore
487487
right,
488488
onclause=on_clause,
489-
isouter=is_outer, # type:ignore
490-
full=full, # type:ignore
489+
isouter=is_outer, # type: ignore
490+
full=full, # type: ignore
491491
)
492492
else:
493493
raise APIError("Unknown from-item: " + dtype)

api/sessions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def __init__(self, connection_id=None, owner: AbstractUser | None = None):
5454
)
5555

5656
engine = _get_engine()
57-
self.connection: DBAPIConnection = engine.connect().connection # type:ignore
57+
self.connection: DBAPIConnection = engine.connect().connection # type: ignore
5858
if connection_id is None:
5959
connection_id = _add_entry(self, _SESSION_CONTEXTS)
6060
elif connection_id not in _SESSION_CONTEXTS:

base/tests/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def get_urlpattern_params(pattern: URLPattern) -> list[str]:
3636
if isinstance(pattern2, RegexPattern):
3737
regex = re.compile(
3838
# TODO: better way than using protected attribute?
39-
pattern2._regex # type:ignore
39+
pattern2._regex # type: ignore
4040
)
4141
return list(regex.groupindex.keys())
4242
elif isinstance(pattern2, RoutePattern):

dataedit/management/commands/create_example_tables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ def handle(self, *args, **opts):
115115
Table.create_with_oedb_table(
116116
name=table_name,
117117
is_sandbox=True, # tests ALWAYS in sandbox
118-
user=user, # type:ignore
118+
user=user, # type: ignore
119119
column_definitions=column_defs,
120120
constraints_definitions=constraint_defs,
121121
)

dataedit/management/commands/migrate_tags.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,11 @@ def handle(self, *args, **options):
3030
color,
3131
usage_tracked_since,
3232
) in con.execute(
33-
text(
34-
"""
33+
text("""
3534
select
3635
id, name_normalized, usage_count, name, color, usage_tracked_since
3736
from public.tags
38-
"""
39-
)
37+
""")
4038
).fetchall():
4139
tag_names[id] = name_normalized
4240
# convert to timezone aware
@@ -51,15 +49,11 @@ def handle(self, *args, **options):
5149
usage_tracked_since=usage_tracked_since,
5250
)
5351

54-
for table_name, tag_id in con.execute(
55-
text(
56-
"""
52+
for table_name, tag_id in con.execute(text("""
5753
select
5854
table_name, tag
5955
from public.table_tags
60-
"""
61-
)
62-
).fetchall():
56+
""")).fetchall():
6357
table = TableOEP.objects.filter(name=table_name).first()
6458
if not table:
6559
print(f"Warning: table does not exist: {table_name}")

dataedit/management/commands/migrate_tags2.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,12 @@ def handle(self, *args, **options):
3636
usage_tracked_since,
3737
category,
3838
) in con.execute(
39-
text(
40-
"""
39+
text("""
4140
select
4241
id, name_normalized, usage_count, name, color, usage_tracked_since,
4342
category
4443
from public.tags
45-
"""
46-
)
44+
""")
4745
).fetchall():
4846
tag_names[tag_id] = tag_name_normalized
4947
tag = TagOEP.objects.filter(name_normalized=tag_name_normalized).first()
@@ -61,18 +59,18 @@ def handle(self, *args, **options):
6159
)
6260
else:
6361
if category:
64-
tag.category = category # type:ignore
62+
tag.category = category # type: ignore
6563
tag.save()
6664

6765
# update factsheets
6866
for factsheet_class in [BasicFactsheet, Energymodel, Energyframework]:
6967
for factsheet in factsheet_class.objects.all():
70-
tag_int_ids = factsheet.tags_TODO_deprecated # type:ignore
68+
tag_int_ids = factsheet.tags_TODO_deprecated # type: ignore
7169
for tag_int_id in tag_int_ids:
7270
if tag_int_id not in tag_names:
7371
print(f"Missing tag: {tag_int_id}")
7472
continue
7573
tag_name_normalized = tag_names[tag_int_id]
7674
tag = TagOEP.objects.get(name_normalized=tag_name_normalized)
77-
factsheet.tags.add(tag) # type:ignore
75+
factsheet.tags.add(tag) # type: ignore
7876
factsheet.save()

dataedit/views.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,7 @@ def iter_oem_key_order(metadata: dict):
732732

733733
opr_result_context = {}
734734
if reviews.exists():
735-
latest_review: PeerReview = reviews.last() # type:ignore (reviews.exists())
735+
latest_review: PeerReview = reviews.last() # type: ignore (reviews.exists())
736736
opr_manager.update_open_since(opr=latest_review)
737737
current_reviewer = opr_manager.load(latest_review).current_reviewer
738738
opr_context.update(
@@ -1435,8 +1435,8 @@ def post(self, request: HttpRequest, table: str, review_id=None) -> HttpResponse
14351435

14361436
# Set new review values and update existing review
14371437
active_peer_review.review = merged_review_data
1438-
active_peer_review.reviewer = user # type:ignore TODO why type warning?
1439-
active_peer_review.contributor = contributor # type:ignore TODO
1438+
active_peer_review.reviewer = user # type: ignore TODO why type warning?
1439+
active_peer_review.contributor = contributor # type: ignore TODO
14401440
active_peer_review.update(review_type=review_post_type)
14411441
else:
14421442
error_msg = (

factsheet/helper.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def build_sector_dropdowns_from_oeo(g: Graph):
192192

193193
# sector individuals: ?sector oeo:is_defined_by ?sd
194194
for sector in g.subjects(PROP_DEFINED_BY, sd):
195-
sec_label = _label(g, sector) # type:ignore
195+
sec_label = _label(g, sector) # type: ignore
196196
definition = g.value(sector, PROP_DEFINITION)
197197

198198
sectors_list.append(

login/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ class myuser(AbstractBaseUser, PermissionHolder):
236236
] # related_name, for static type checking
237237

238238
USERNAME_FIELD = "name"
239-
REQUIRED_FIELDS = [name] # type:ignore TODO: why do we need this?
239+
REQUIRED_FIELDS = [name] # type: ignore TODO: why do we need this?
240240

241241
objects = OEPUserManager()
242242

0 commit comments

Comments
 (0)