Skip to content

Commit d9057bb

Browse files
committed
Add ruff and ty
1 parent e870c3a commit d9057bb

File tree

9 files changed

+91
-43
lines changed

9 files changed

+91
-43
lines changed

.github/workflows/test-suite.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,12 +85,12 @@ jobs:
8585
- name: Install build dependencies
8686
if: steps.cache.outputs.cache-hit != 'true'
8787
run: pip install hatch
88-
- name: "Run linting"
88+
- name: "Run linting checks"
8989
if: steps.filters.outputs.src == 'true'
90-
run: "hatch fmt --check"
91-
# - name: "Run mypy"
92-
# if: steps.filters.outputs.src == 'true'
93-
# run: "hatch run test:check_types"
90+
run: "hatch run ruff"
91+
- name: "Run typing checks"
92+
if: steps.filters.outputs.src == 'true'
93+
run: "hatch run test:check_types"
9494
- name: "Run tests"
9595
if: steps.filters.outputs.src == 'true' || steps.filters.outputs.workflows == 'true' || github.event.schedule != ''
9696
# test with xdist as still segfaults occur

Taskfile.yaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,26 @@
11
version: 3
22

33
tasks:
4+
ruff:
5+
desc: Runs ruff linting checks
6+
cmds:
7+
- hatch run ruff
8+
9+
lint:
10+
desc: Runs linting checks (ruff + ty)
11+
cmds:
12+
- hatch run lint
13+
14+
format:
15+
desc: Formats the codebase and re-runs checks
16+
cmds:
17+
- hatch run format
18+
19+
ty:
20+
desc: Runs type checking with ty
21+
cmds:
22+
- hatch run test:check_types
23+
424
docs_prepare:
525
desc: Prepares documentation sources for Zensical
626
cmds:

databasez/interfaces.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,7 @@ async def batched_iterate(
293293
Yields:
294294
Sequence[Record]: A batch of result rows.
295295
"""
296-
# mypy needs async iterators to contain a `yield`
297-
# https://github.com/python/mypy/issues/5385#issuecomment-407281656
296+
# Type checkers need async iterators to contain a `yield`.
298297
yield True # type: ignore
299298

300299
async def iterate(

docs/contributing.md

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,24 @@ $ hatch test -- tests/test_database_url.py -q
5757
## Linting and formatting
5858

5959
```shell
60-
$ hatch fmt --check
61-
$ hatch fmt
60+
$ hatch run ruff
61+
$ hatch run lint
62+
$ hatch run format
63+
```
64+
65+
## Type checking
66+
67+
```shell
68+
$ hatch run test:check_types
69+
```
70+
71+
Taskfile shortcut:
72+
73+
```shell
74+
$ task ruff
75+
$ task ty
76+
$ task lint
77+
$ task format
6278
```
6379

6480
## Documentation workflow (Zensical)

docs_src/transactions/async_context_connection.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33

44
async def main() -> None:
5-
async with Database("sqlite+aiosqlite:///example.db") as database, database.connection() as connection:
5+
async with (
6+
Database("sqlite+aiosqlite:///example.db") as database,
7+
database.connection() as connection,
8+
):
69
await connection.execute(
710
"CREATE TABLE IF NOT EXISTS notes (id INTEGER PRIMARY KEY, text VARCHAR(100))"
811
)
@@ -13,4 +16,6 @@ async def main() -> None:
1316
)
1417

1518
async with connection.transaction(force_rollback=True):
16-
await connection.execute("INSERT INTO notes(text) VALUES (:text)", {"text": "rolled back"})
19+
await connection.execute(
20+
"INSERT INTO notes(text) VALUES (:text)", {"text": "rolled back"}
21+
)

docs_src/transactions/async_context_database.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,6 @@ async def main() -> None:
1313
)
1414

1515
async with database.transaction(force_rollback=True):
16-
await database.execute("INSERT INTO notes(text) VALUES (:text)", {"text": "rolled back"})
16+
await database.execute(
17+
"INSERT INTO notes(text) VALUES (:text)", {"text": "rolled back"}
18+
)

docs_src/transactions/force_rollback_transaction.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ async def test_foo() -> None:
1414
await database.execute("INSERT INTO notes(text) VALUES (:text)", {"text": "saved"})
1515

1616
async with database.transaction(force_rollback=True):
17-
await database.execute("INSERT INTO notes(text) VALUES (:text)", {"text": "rolled"})
17+
await database.execute(
18+
"INSERT INTO notes(text) VALUES (:text)", {"text": "rolled"}
19+
)
1820

1921
rows = await database.fetch_all("SELECT text FROM notes ORDER BY id")
2022
assert [row.text for row in rows] == ["saved"]

pyproject.toml

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,31 @@ all = ["databasez[jdbc,mysql,aiomysql,odbc,postgresql,sqlite]"]
7575
path = "databasez/__init__.py"
7676

7777

78-
[tool.mypy]
79-
strict = true
80-
disallow_any_generics = false
81-
disallow_untyped_decorators = true
82-
implicit_reexport = true
83-
disallow_incomplete_defs = true
84-
disable_error_code = "attr-defined"
85-
disallow_untyped_defs = true
86-
ignore_missing_imports = true
87-
no_implicit_optional = true
78+
[tool.ty]
79+
80+
[tool.ty.src]
81+
exclude = ["docs_src/"]
82+
83+
[tool.ty.terminal]
84+
error-on-warning = true
85+
86+
[tool.ty.rules]
87+
unresolved-import = "ignore"
88+
redundant-cast = "ignore"
89+
unused-type-ignore-comment = "ignore"
90+
possibly-missing-attribute = "ignore"
91+
unresolved-attribute = "ignore"
92+
call-top-callable = "ignore"
93+
call-non-callable = "ignore"
94+
invalid-type-form = "ignore"
95+
invalid-parameter-default = "ignore"
96+
invalid-method-override = "ignore"
97+
invalid-assignment = "ignore"
98+
invalid-argument-type = "ignore"
99+
conflicting-declarations = "ignore"
100+
unknown-argument = "ignore"
101+
unsupported-operator = "ignore"
102+
invalid-await = "ignore"
88103

89104
[tool.ruff]
90105
extend-exclude = ["docs"]
@@ -123,20 +138,6 @@ known-third-party = ["ravyn", "starlette", "lilya"]
123138
max-line-length = 120
124139
max-doc-length = 120
125140

126-
[[tool.mypy.overrides]]
127-
module = "databasez.tests.*"
128-
ignore_missing_imports = true
129-
check_untyped_defs = true
130-
131-
[[tool.mypy.overrides]]
132-
module = ["sqlalchemy.*", "asyncpg", "alembic", "sqlalchemy_utils.*"]
133-
ignore_missing_imports = true
134-
ignore_errors = true
135-
136-
[[tool.mypy.overrides]]
137-
module = "docs_src.*"
138-
ignore_errors = true
139-
140141
[tool.pytest.ini_options]
141142
addopts = [
142143
"--strict-config",
@@ -159,6 +160,8 @@ include = ["/databasez"]
159160
[tool.hatch.envs.default]
160161
features = ["all"]
161162
extra-dependencies = [
163+
"ty",
164+
"ruff>=0.3.0,<5.0.0",
162165
# for debugging
163166
"sqlalchemy_utils",
164167
"ipdb>=0.13.13",
@@ -168,6 +171,10 @@ extra-dependencies = [
168171
[tool.hatch.envs.default.scripts]
169172
clean_pyc = "find . -type f -name \"*.pyc\" -delete"
170173
clean_pycache = "find . -type d -name \"*__pycache__*\" -delete"
174+
check_types = "ty check --error-on-warning databasez"
175+
ruff = "hatch fmt --check"
176+
lint = "hatch fmt --check && ty check --error-on-warning databasez"
177+
format = "hatch fmt && hatch fmt --check && ty check --error-on-warning databasez"
171178

172179
[tool.hatch.envs.docs]
173180
dependencies = [
@@ -185,10 +192,10 @@ dev = "python scripts/docs.py serve"
185192
[tool.hatch.envs.test]
186193
# type-checking
187194
features = ["all"]
188-
extra-dependencies = ["mypy>=1.1.0,<2.0.0"]
195+
extra-dependencies = ["ty"]
189196

190197
[tool.hatch.envs.test.scripts]
191-
check_types = "mypy -p databasez"
198+
check_types = "ty check --error-on-warning databasez"
192199

193200
[tool.hatch.envs.hatch-static-analysis]
194201
# disables custom ruff rules, required to align with pre-commit
@@ -204,7 +211,7 @@ extra-dependencies = [
204211
"sqlalchemy_utils",
205212
"ipdb>=0.13.13",
206213
"ravyn>=0.3.8",
207-
"mypy>=1.1.0,<2.0.0",
214+
"ty",
208215
"starlette>=0.26.1",
209216
"httpx",
210217
"psycopg[binary]",

scripts/clean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@ fi
1515
if [ -d 'databasez.egg-info' ] ; then
1616
rm -r databasez.egg-info
1717
fi
18-
if [ -d '.mypy_cache' ] ; then
19-
rm -r .mypy_cache
20-
fi
2118
if [ -d '.pytest_cache' ] ; then
2219
rm -r .pytest_cache
2320
fi

0 commit comments

Comments
 (0)