Skip to content

Upgrade syntax for Python 3.9+ #647

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ jobs:
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13"]
numpy: [0, 1]
os: [ubuntu-latest, macos-latest, windows-latest, macos-14]
# Skip 3.9 on macos-14 - it only has 3.10+
exclude:
- python-version: "3.9"
os: macos-14
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
Expand Down
1 change: 0 additions & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from subprocess import Popen, PIPE
from beanbag_docutils.sphinx.ext.github import github_linkcode_resolve
Expand Down
102 changes: 59 additions & 43 deletions docs/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -127,19 +127,21 @@
}
],
"source": [
"db[\"creatures\"].insert_all([{\n",
" \"name\": \"Cleo\",\n",
" \"species\": \"dog\",\n",
" \"age\": 6\n",
"}, {\n",
" \"name\": \"Lila\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.8,\n",
"}, {\n",
" \"name\": \"Bants\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.8,\n",
"}])"
"db[\"creatures\"].insert_all(\n",
" [\n",
" {\"name\": \"Cleo\", \"species\": \"dog\", \"age\": 6},\n",
" {\n",
" \"name\": \"Lila\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.8,\n",
" },\n",
" {\n",
" \"name\": \"Bants\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.8,\n",
" },\n",
" ]\n",
")"
]
},
{
Expand Down Expand Up @@ -341,7 +343,9 @@
}
],
"source": [
"list(db.query(\"select * from creatures where species = :species\", {\"species\": \"chicken\"}))"
"list(\n",
" db.query(\"select * from creatures where species = :species\", {\"species\": \"chicken\"})\n",
")"
]
},
{
Expand Down Expand Up @@ -506,22 +510,24 @@
}
],
"source": [
"db[\"creatures\"].insert_all([{\n",
" \"id\": 1,\n",
" \"name\": \"Cleo\",\n",
" \"species\": \"dog\",\n",
" \"age\": 6\n",
"}, {\n",
" \"id\": 2,\n",
" \"name\": \"Lila\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.8,\n",
"}, {\n",
" \"id\": 3,\n",
" \"name\": \"Bants\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.8,\n",
"}], pk=\"id\")"
"db[\"creatures\"].insert_all(\n",
" [\n",
" {\"id\": 1, \"name\": \"Cleo\", \"species\": \"dog\", \"age\": 6},\n",
" {\n",
" \"id\": 2,\n",
" \"name\": \"Lila\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.8,\n",
" },\n",
" {\n",
" \"id\": 3,\n",
" \"name\": \"Bants\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.8,\n",
" },\n",
" ],\n",
" pk=\"id\",\n",
")"
]
},
{
Expand Down Expand Up @@ -575,17 +581,23 @@
}
],
"source": [
"table.insert_all([{\n",
" \"id\": 4,\n",
" \"name\": \"Azi\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.8,\n",
"}, {\n",
" \"id\": 5,\n",
" \"name\": \"Snowy\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.9,\n",
"}], pk=\"id\")"
"table.insert_all(\n",
" [\n",
" {\n",
" \"id\": 4,\n",
" \"name\": \"Azi\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.8,\n",
" },\n",
" {\n",
" \"id\": 5,\n",
" \"name\": \"Snowy\",\n",
" \"species\": \"chicken\",\n",
" \"age\": 0.9,\n",
" },\n",
" ],\n",
" pk=\"id\",\n",
")"
]
},
{
Expand Down Expand Up @@ -1006,7 +1018,9 @@
}
],
"source": [
"list(db.query(\"\"\"\n",
"list(\n",
" db.query(\n",
" \"\"\"\n",
" select\n",
" creatures.id,\n",
" creatures.name,\n",
Expand All @@ -1015,7 +1029,9 @@
" species.species\n",
" from creatures\n",
" join species on creatures.species_id = species.id\n",
"\"\"\"))"
"\"\"\"\n",
" )\n",
")"
]
},
{
Expand Down
3 changes: 1 addition & 2 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
from setuptools import setup, find_packages
import io
import os

VERSION = "3.38"


def get_long_description():
with io.open(
with open(
os.path.join(os.path.dirname(os.path.abspath(__file__)), "README.md"),
encoding="utf8",
) as fp:
Expand Down
50 changes: 24 additions & 26 deletions sqlite_utils/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ def enable_counts(path, tables, load_extension):
# Check all tables exist
bad_tables = [table for table in tables if not db[table].exists()]
if bad_tables:
raise click.ClickException("Invalid tables: {}".format(bad_tables))
raise click.ClickException(f"Invalid tables: {bad_tables}")
for table in tables:
db[table].enable_counts()

Expand Down Expand Up @@ -1005,7 +1005,7 @@ def insert_upsert_implementation(
reader = csv_std.reader(decoded, **csv_reader_args)
first_row = next(reader)
if no_headers:
headers = ["untitled_{}".format(i + 1) for i in range(len(first_row))]
headers = [f"untitled_{i + 1}" for i in range(len(first_row))]
reader = itertools.chain([first_row], reader)
else:
headers = first_row
Expand Down Expand Up @@ -1568,7 +1568,7 @@ def create_table(
ctype = columns.pop(0)
if ctype.upper() not in VALID_COLUMN_TYPES:
raise click.ClickException(
"column types must be one of {}".format(VALID_COLUMN_TYPES)
f"column types must be one of {VALID_COLUMN_TYPES}"
)
coltypes[name] = ctype.upper()
# Does table already exist?
Expand Down Expand Up @@ -1612,7 +1612,7 @@ def duplicate(path, table, new_table, ignore, load_extension):
db[table].duplicate(new_table)
except NoTable:
if not ignore:
raise click.ClickException('Table "{}" does not exist'.format(table))
raise click.ClickException(f'Table "{table}" does not exist')


@cli.command(name="rename-table")
Expand All @@ -1636,7 +1636,7 @@ def rename_table(path, table, new_name, ignore, load_extension):
except sqlite3.OperationalError as ex:
if not ignore:
raise click.ClickException(
'Table "{}" could not be renamed. {}'.format(table, str(ex))
f'Table "{table}" could not be renamed. {str(ex)}'
)


Expand All @@ -1662,7 +1662,7 @@ def drop_table(path, table, ignore, load_extension):
try:
db[table].drop(ignore=ignore)
except OperationalError:
raise click.ClickException('Table "{}" does not exist'.format(table))
raise click.ClickException(f'Table "{table}" does not exist')


@cli.command(name="create-view")
Expand Down Expand Up @@ -1732,7 +1732,7 @@ def drop_view(path, view, ignore, load_extension):
try:
db[view].drop(ignore=ignore)
except OperationalError:
raise click.ClickException('View "{}" does not exist'.format(view))
raise click.ClickException(f'View "{view}" does not exist')


@cli.command()
Expand Down Expand Up @@ -1944,7 +1944,7 @@ def memory(
file_path = pathlib.Path(path)
stem = file_path.stem
if stem_counts.get(stem):
file_table = "{}_{}".format(stem, stem_counts[stem])
file_table = f"{stem}_{stem_counts[stem]}"
else:
file_table = stem
stem_counts[stem] = stem_counts.get(stem, 1) + 1
Expand All @@ -1961,12 +1961,12 @@ def memory(
if tracker is not None:
db[file_table].transform(types=tracker.types)
# Add convenient t / t1 / t2 views
view_names = ["t{}".format(i + 1)]
view_names = [f"t{i + 1}"]
if i == 0:
view_names.append("t")
for view_name in view_names:
if not db[view_name].exists():
db.create_view(view_name, "select * from [{}]".format(file_table))
db.create_view(view_name, f"select * from [{file_table}]")

if fp:
fp.close()
Expand Down Expand Up @@ -2127,19 +2127,17 @@ def search(
# Check table exists
table_obj = db[dbtable]
if not table_obj.exists():
raise click.ClickException("Table '{}' does not exist".format(dbtable))
raise click.ClickException(f"Table '{dbtable}' does not exist")
if not table_obj.detect_fts():
raise click.ClickException(
"Table '{}' is not configured for full-text search".format(dbtable)
f"Table '{dbtable}' is not configured for full-text search"
)
if column:
# Check they all exist
table_columns = table_obj.columns_dict
for c in column:
if c not in table_columns:
raise click.ClickException(
"Table '{}' has no column '{}".format(dbtable, c)
)
raise click.ClickException(f"Table '{dbtable}' has no column '{c}")
sql = table_obj.search_sql(columns=column, order_by=order, limit=limit)
if show_sql:
click.echo(sql)
Expand All @@ -2165,7 +2163,7 @@ def search(
except click.ClickException as e:
if "malformed MATCH expression" in str(e) or "unterminated string" in str(e):
raise click.ClickException(
"{}\n\nTry running this again with the --quote option".format(str(e))
f"{str(e)}\n\nTry running this again with the --quote option"
)
else:
raise
Expand Down Expand Up @@ -2230,16 +2228,16 @@ def rows(
"""
columns = "*"
if column:
columns = ", ".join("[{}]".format(c) for c in column)
sql = "select {} from [{}]".format(columns, dbtable)
columns = ", ".join(f"[{c}]" for c in column)
sql = f"select {columns} from [{dbtable}]"
if where:
sql += " where " + where
if order:
sql += " order by " + order
if limit:
sql += " limit {}".format(limit)
sql += f" limit {limit}"
if offset:
sql += " offset {}".format(offset)
sql += f" offset {offset}"
ctx.invoke(
query,
path=path,
Expand Down Expand Up @@ -2494,7 +2492,7 @@ def transform(
for column, ctype in type:
if ctype.upper() not in VALID_COLUMN_TYPES:
raise click.ClickException(
"column types must be one of {}".format(VALID_COLUMN_TYPES)
f"column types must be one of {VALID_COLUMN_TYPES}"
)
types[column] = ctype.upper()

Expand Down Expand Up @@ -2728,7 +2726,7 @@ def _content_text(p):
except UnicodeDecodeErrorForPath as e:
raise click.ClickException(
UNICODE_ERROR.format(
"Could not read file '{}' as text\n\n{}".format(e.path, e.exception)
f"Could not read file '{e.path}' as text\n\n{e.exception}"
)
)

Expand Down Expand Up @@ -3010,7 +3008,7 @@ def preview(v):
""".format(
column=columns[0],
table=table,
where=" where {}".format(where) if where is not None else "",
where=f" where {where}" if where is not None else "",
)
for row in db.conn.execute(sql, where_args).fetchall():
click.echo(str(row[0]))
Expand Down Expand Up @@ -3181,7 +3179,7 @@ def _render_common(title, values):
return ""
lines = [title]
for value, count in values:
lines.append(" {}: {}".format(count, value))
lines.append(f" {count}: {value}")
return "\n".join(lines)


Expand Down Expand Up @@ -3261,7 +3259,7 @@ def json_binary(value):
def verify_is_dict(doc):
if not isinstance(doc, dict):
raise click.ClickException(
"Rows must all be dictionaries, got: {}".format(repr(doc)[:1000])
f"Rows must all be dictionaries, got: {repr(doc)[:1000]}"
)
return doc

Expand All @@ -3286,7 +3284,7 @@ def _register_functions(db, functions):
try:
exec(functions, globals)
except SyntaxError as ex:
raise click.ClickException("Error in functions definition: {}".format(ex))
raise click.ClickException(f"Error in functions definition: {ex}")
# Register all callables in the locals dict:
for name, value in globals.items():
if callable(value) and not name.startswith("_"):
Expand Down
Loading
Loading