Skip to content

Commit c0cf990

Browse files
authored
Linting fixes (#17)
* Add pre-commit hook for `mypy` to catch typing errors * Linting fixes for entire library. * Fix all mypy lints. * Replace `pre-commit` runner for `mypy` with CI job. * Fix some Ruff lints + format. * Minor logic fix. * Change import order. * Some typing fixes. * Deduplicate the fields in `MapJoin`. * Reintroduce `head()`, with type checks. * `Term` -> `LogicNode` in a few places. * Better performance in `query_property`. * Use `dict.setdefault`. * Replace `is_expr` and `NodeWithFields` by `LogicExpression` and `LogicLeaf`.
1 parent fb79079 commit c0cf990

File tree

25 files changed

+1012
-621
lines changed

25 files changed

+1012
-621
lines changed

.github/workflows/ci.yml

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
1+
defaults:
2+
run:
3+
shell: bash -el {0}
4+
15
name: CI
26
jobs:
37
test:
4-
defaults:
5-
run:
6-
shell: bash -el {0}
78
strategy:
89
matrix:
910
os: [ubuntu-latest]
@@ -17,7 +18,7 @@ jobs:
1718
runs-on: ${{ matrix.os }}
1819
steps:
1920
- name: Checkout Repo
20-
uses: actions/checkout@v3
21+
uses: actions/checkout@v4
2122
- uses: actions/setup-python@v5
2223
with:
2324
python-version: ${{ matrix.python }}
@@ -29,7 +30,25 @@ jobs:
2930
- name: Run tests
3031
run: |
3132
poetry run pytest --junit-xml=test-${{ matrix.os }}-Python-${{ matrix.python }}.xml
32-
- uses: codecov/codecov-action@v3
33+
- uses: codecov/codecov-action@v5
34+
mypy:
35+
runs-on: ubuntu-latest
36+
steps:
37+
- name: Checkout Repo
38+
uses: actions/checkout@v4
39+
- uses: actions/setup-python@v5
40+
with:
41+
python-version: 3.12
42+
- name: Install Poetry
43+
uses: snok/install-poetry@v1
44+
- name: Install package
45+
run: |
46+
poetry install --with test
47+
- name: Run tests
48+
run: |
49+
poetry run mypy .
50+
51+
3352
3453
on:
3554
# Trigger the workflow on push or pull request,

pixi.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ sparse = "*"
2424
numba = ">=0.60"
2525
scipy = "*"
2626
numpy = "==2.*"
27+
mypy = ">=1.15.0,<2"
2728

2829
[feature.test.tasks]
2930
test = { cmd = "pytest", depends-on = ["compile"] }

pyproject.toml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,28 @@ pytest-cov = "^4.1.0"
1818
sparse = "^0.16.0"
1919
scipy = "^1.7"
2020
numba = "^0.61.0"
21+
mypy = "^1.15.0"
2122

2223
[build-system]
2324
requires = ["poetry-core>=1.0.8"]
2425
build-backend = "poetry.core.masonry.api"
26+
27+
[tool.ruff.lint]
28+
select = ["F", "E", "W", "I", "B", "UP", "YTT", "BLE", "C4", "T10", "ISC", "ICN", "PIE", "PYI", "RSE", "RET", "SIM", "PGH", "FLY", "NPY", "PERF"]
29+
30+
[tool.ruff.lint.isort.sections]
31+
numpy = ["numpy", "numpy.*", "scipy", "scipy.*"]
32+
33+
[tool.ruff.format]
34+
quote-style = "double"
35+
docstring-code-format = true
36+
37+
[tool.ruff.lint.isort]
38+
section-order = [
39+
"future",
40+
"standard-library",
41+
"numpy",
42+
"third-party",
43+
"first-party",
44+
"local-folder",
45+
]

src/finch/__init__.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,31 @@
11
from . import finch_logic
2-
from .interface import *
2+
from .interface import (
3+
compute,
4+
elementwise,
5+
expand_dims,
6+
fuse,
7+
fused,
8+
identify,
9+
lazy,
10+
multiply,
11+
permute_dims,
12+
prod,
13+
reduce,
14+
squeeze,
15+
)
16+
17+
__all__ = [
18+
"lazy",
19+
"compute",
20+
"finch_logic",
21+
"fuse",
22+
"fused",
23+
"permute_dims",
24+
"expand_dims",
25+
"squeeze",
26+
"identify",
27+
"reduce",
28+
"elementwise",
29+
"prod",
30+
"multiply",
31+
]

src/finch/algebra/__init__.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
1-
from .algebra import *
1+
from .algebra import (
2+
element_type,
3+
fill_value,
4+
fixpoint_type,
5+
init_value,
6+
is_associative,
7+
query_property,
8+
register_property,
9+
return_type,
10+
)
211

312
__all__ = [
413
"fill_value",
@@ -9,4 +18,4 @@
918
"is_associative",
1019
"query_property",
1120
"register_property",
12-
]
21+
]

0 commit comments

Comments
 (0)