Skip to content

Commit 48ef551

Browse files
committed
Fix remaining Ruff errors with GPT-5.6 Sol high
https://gist.github.com/simonw/6da7906a9fea6e90da131c21a9055199
1 parent 6ee502d commit 48ef551

16 files changed

Lines changed: 164 additions & 190 deletions

‎docs/conf.py‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
1-
#!/usr/bin/env python3
2-
31
import inspect
42
import sys
53
from pathlib import Path
6-
from subprocess import PIPE, Popen, check_output
4+
from subprocess import PIPE, CalledProcessError, Popen, check_output
75

86
# This file is execfile()d with the current directory set to its
97
# containing dir.
@@ -49,7 +47,7 @@
4947
def _linkcode_git_ref():
5048
try:
5149
return check_output(["git", "rev-parse", "HEAD"]).decode("utf8").strip()
52-
except Exception:
50+
except (CalledProcessError, OSError):
5351
return "main"
5452

5553

@@ -78,7 +76,7 @@ def linkcode_resolve(domain, info):
7876
obj = inspect.unwrap(obj)
7977
source_file = inspect.getsourcefile(obj)
8078
_, line_number = inspect.getsourcelines(obj)
81-
except Exception:
79+
except (OSError, TypeError, ValueError):
8280
return None
8381

8482
if source_file is None:

‎sqlite_utils/cli.py‎

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import json
99
import os
1010
import pathlib
11-
import pdb
11+
import pdb # noqa: T100
1212
import sys
1313
import textwrap
1414
from datetime import datetime, timezone
@@ -72,7 +72,7 @@ def _close_databases(ctx):
7272
for db in ctx.meta.get("_databases_to_close", []):
7373
try:
7474
db.close()
75-
except Exception:
75+
except sqlite3.Error:
7676
pass
7777

7878

@@ -1840,9 +1840,7 @@ def rename_table(path, table, new_name, ignore, load_extension):
18401840
db.rename_table(table, new_name)
18411841
except sqlite3.OperationalError as ex:
18421842
if not ignore:
1843-
raise click.ClickException(
1844-
f'Table "{table}" could not be renamed. {ex!s}'
1845-
)
1843+
raise click.ClickException(f'Table "{table}" could not be renamed. {ex!s}')
18461844

18471845

18481846
@cli.command(name="drop-table")
@@ -2378,9 +2376,7 @@ def search(
23782376
table_columns = table_obj.columns_dict
23792377
for c in column:
23802378
if c not in table_columns:
2381-
raise click.ClickException(
2382-
f"Table '{dbtable}' has no column '{c}"
2383-
)
2379+
raise click.ClickException(f"Table '{dbtable}' has no column '{c}")
23842380
sql = table_obj.search_sql(columns=column, order_by=order, limit=limit)
23852381
if show_sql:
23862382
click.echo(sql)
@@ -2953,7 +2949,7 @@ def yield_paths_and_relative_paths():
29532949
with progressbar(paths_and_relative_paths, silent=silent) as bar:
29542950

29552951
def to_insert():
2956-
for path, relative_path in bar:
2952+
for file_path, relative_path in bar:
29572953
row = {}
29582954
# content_text is special case as it considers 'encoding'
29592955

@@ -2965,27 +2961,29 @@ def _content_text(p):
29652961
raise UnicodeDecodeErrorForPath(e, resolved)
29662962

29672963
lookups = dict(FILE_COLUMNS, content_text=_content_text)
2968-
if path == "-":
2964+
if file_path == "-":
29692965
stdin_data = sys.stdin.buffer.read()
29702966
# We only support a subset of columns for this case
29712967
lookups = {
29722968
"name": lambda p: name or "-",
29732969
"path": lambda p: name or "-",
2974-
"content": lambda p: stdin_data,
2975-
"content_text": lambda p: stdin_data.decode(
2970+
"content": lambda p, data=stdin_data: data,
2971+
"content_text": lambda p, data=stdin_data: data.decode(
29762972
encoding or "utf-8"
29772973
),
2978-
"sha256": lambda p: hashlib.sha256(stdin_data).hexdigest(),
2979-
"md5": lambda p: hashlib.md5(stdin_data).hexdigest(),
2980-
"size": lambda p: len(stdin_data),
2974+
"sha256": lambda p, data=stdin_data: hashlib.sha256(
2975+
data
2976+
).hexdigest(),
2977+
"md5": lambda p, data=stdin_data: hashlib.md5(data).hexdigest(),
2978+
"size": lambda p, data=stdin_data: len(data),
29812979
}
29822980
for coldef in column:
29832981
if ":" in coldef:
29842982
colname, coltype = coldef.rsplit(":", 1)
29852983
else:
29862984
colname, coltype = coldef, coldef
29872985
try:
2988-
value = lookups[coltype](path)
2986+
value = lookups[coltype](file_path)
29892987
row[colname] = value
29902988
except KeyError:
29912989
raise click.ClickException(
@@ -3314,7 +3312,7 @@ def preview(v):
33143312
def wrapped_fn(value):
33153313
try:
33163314
return fn_(value)
3317-
except Exception as ex:
3315+
except Exception as ex: # noqa: BLE001
33183316
print("\nException raised, dropping into pdb...:", ex)
33193317
pdb.post_mortem(ex.__traceback__)
33203318
sys.exit(1)
@@ -3477,7 +3475,7 @@ def _load_migration_sets(files):
34773475
"__file__": str(filepath),
34783476
"__name__": "__sqlite_utils_migration__",
34793477
}
3480-
exec(code, namespace)
3478+
exec(code, namespace) # noqa: S102
34813479
migration_sets.extend(
34823480
obj for obj in namespace.values() if _compatible_migration_set(obj)
34833481
)
@@ -3587,9 +3585,7 @@ def migrate(db_path, migrations, stop_before, list_, verbose):
35873585
names = {m.name for m in migration_set.pending(db)}
35883586
names.update(m.name for m in migration_set.applied(db))
35893587
known_names.update(names)
3590-
known_names.update(
3591-
f"{migration_set.name}:{name}" for name in names
3592-
)
3588+
known_names.update(f"{migration_set.name}:{name}" for name in names)
35933589
unknown = [value for value in stop_before if value not in known_names]
35943590
if unknown:
35953591
raise click.ClickException(
@@ -3766,7 +3762,7 @@ def _register_functions(db, functions):
37663762
sqlite3.enable_callback_tracebacks(True)
37673763
globals = {}
37683764
try:
3769-
exec(functions, globals)
3765+
exec(functions, globals) # noqa: S102
37703766
except SyntaxError as ex:
37713767
raise click.ClickException(f"Error in functions definition: {ex}")
37723768
# Register all callables in the locals dict:
@@ -3792,7 +3788,7 @@ def _rows_from_code(code):
37923788
raise click.ClickException(f"File not found: {code}")
37933789
namespace = {}
37943790
try:
3795-
exec(code, namespace)
3791+
exec(code, namespace) # noqa: S102
37963792
except SyntaxError as ex:
37973793
raise click.ClickException(f"Error in --code: {ex}")
37983794
rows = namespace.get("rows")

0 commit comments

Comments
 (0)