Skip to content

Commit 01046c3

Browse files
authored
Typecheck project with ty (#204)
These changes add `ty` as a development dependency and enforce typechecking in CI. To typecheck locally: ```sh uv run ty check ```
1 parent c0def59 commit 01046c3

7 files changed

Lines changed: 1619 additions & 1364 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,15 @@ jobs:
1616
- uses: actions/checkout@v5
1717
- uses: astral-sh/setup-uv@v7
1818
- run: |
19-
uv run ruff check .
19+
uv run ruff check
20+
21+
Typecheck:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: actions/checkout@v5
25+
- uses: astral-sh/setup-uv@v7
26+
- run: |
27+
uv run ty check
2028
2129
Test:
2230
runs-on: ubuntu-latest

examples/JupyterServer.ipynb

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"cell_type": "code",
55
"execution_count": null,
6-
"id": "f1562cea-288f-4817-8ca7-606cd104630e",
6+
"id": "3f95a08d",
77
"metadata": {},
88
"outputs": [],
99
"source": [
@@ -13,7 +13,7 @@
1313
{
1414
"cell_type": "code",
1515
"execution_count": null,
16-
"id": "db2277b1",
16+
"id": "25f7dab3",
1717
"metadata": {},
1818
"outputs": [],
1919
"source": [
@@ -26,13 +26,13 @@
2626
{
2727
"cell_type": "code",
2828
"execution_count": null,
29-
"id": "2e2c753f-fb13-4d54-b031-10cf5865e138",
29+
"id": "caf312ad",
3030
"metadata": {},
3131
"outputs": [],
3232
"source": [
3333
"from dataclasses import dataclass\n",
3434
"\n",
35-
"from clodius.tiles.cooler import tiles, tileset_info\n",
35+
"from clodius.tiles.cooler import tiles, tileset_info # ty:ignore[unresolved-import]\n",
3636
"\n",
3737
"\n",
3838
"@dataclass\n",
@@ -54,31 +54,31 @@
5454
{
5555
"cell_type": "code",
5656
"execution_count": null,
57-
"id": "d2b9ae4d-85d0-4545-aeef-073ad7d0d4e9",
57+
"id": "866266ec",
5858
"metadata": {},
5959
"outputs": [],
6060
"source": []
6161
},
6262
{
6363
"cell_type": "code",
6464
"execution_count": null,
65-
"id": "2a69dbe9-ad50-4e98-ac3b-b05285703760",
65+
"id": "78d4ccb4",
6666
"metadata": {},
6767
"outputs": [],
6868
"source": []
6969
},
7070
{
7171
"cell_type": "code",
7272
"execution_count": null,
73-
"id": "f4ea4dec-135f-49c7-b7ef-ff0c0ece8b45",
73+
"id": "fb5ee4a8",
7474
"metadata": {},
7575
"outputs": [],
7676
"source": []
7777
},
7878
{
7979
"cell_type": "code",
8080
"execution_count": null,
81-
"id": "8e571a51-4b09-4da7-8d65-af28a5cf4703",
81+
"id": "3f3151e0",
8282
"metadata": {},
8383
"outputs": [],
8484
"source": []
@@ -105,4 +105,4 @@
105105
},
106106
"nbformat": 4,
107107
"nbformat_minor": 5
108-
}
108+
}

pyproject.toml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ requires-python = ">=3.8"
3434
urls = { homepage = "https://github.com/higlass/higlass-python" }
3535

3636
[dependency-groups]
37-
dev = ["anywidget[dev]", "jupyterlab", "pytest", "ruff"]
37+
dev = [
38+
"anywidget[dev]>=0.9.13",
39+
# TODO Add for typechecking after we drop 3.8 support
40+
# "clodius>=0.20.4",
41+
"jupyterlab>=4.3.5",
42+
"pytest>=8.3.5",
43+
"ruff>=0.15.4",
44+
"ty>=0.0.19",
45+
]
3846

3947
[tool.hatch.build.targets.wheel]
4048
packages = ["src/higlass"]
@@ -65,5 +73,9 @@ extend-select = [
6573
"examples/*.ipynb" = [
6674
"F811", # redefintion
6775
]
76+
77+
[tool.ty.src]
78+
exclude = ["examples/Plugin.ipynb", "docs/conf.py", "docs/build.py"]
79+
6880
[tool.uv]
6981
required-version = ">=0.10.0"

src/higlass/api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@
4848

4949
class _PropertiesMixin:
5050
def properties(
51-
self: utils.ModelT, # type: ignore
51+
self: utils.ModelT,
5252
inplace: bool = False,
53-
**fields, # type: ignore
54-
) -> utils.ModelT: # type: ignore
53+
**fields,
54+
) -> utils.ModelT:
5555
"""Configures top-level properties.
5656
5757
Updates top-level properties for a Track, View, or Viewconf. This
@@ -85,10 +85,10 @@ def properties(
8585

8686
class _OptionsMixin:
8787
def opts(
88-
self: TrackT, # type: ignore
88+
self: TrackT,
8989
inplace: bool = False,
9090
**options,
91-
) -> TrackT: # type: ignore
91+
) -> TrackT:
9292
"""Configures options for a Track.
9393
9494
A convenience method to update `track.options`.

src/higlass/tilesets.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,10 +192,12 @@ def load(filepath: str | pathlib.Path) -> ClodiusTileset:
192192

193193

194194
def chromsizes(filepath: str) -> ClodiusTileset:
195-
from clodius.tiles.chromsizes import tileset_info
195+
from clodius.tiles.chromsizes import tileset_info # ty:ignore[unresolved-import]
196196

197197
return ClodiusTileset(
198-
datatype="chromsizes", tiles_impl=None, info_impl=lambda: tileset_info(filepath)
198+
datatype="chromsizes",
199+
tiles_impl=lambda _: {}, # chromsizes has no tiles endpoint
200+
info_impl=lambda: tileset_info(filepath),
199201
)
200202

201203

test/test_api.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
)
8686
def test_creates_correct_track(args: str | tuple, expected: hg.Track):
8787
track_type, kwargs = (args, {}) if isinstance(args, str) else args
88-
track = hg.track(track_type, **kwargs) # type: ignore
88+
track = hg.track(track_type, **kwargs)
8989
assert isinstance(track, expected) # type: ignore
9090
assert track.type == track_type
9191

@@ -227,15 +227,16 @@ class PileupTrack(hg.PluginTrack):
227227
}
228228

229229
# Create and use the custom track
230-
pileup_track = PileupTrack(data=pileup_data)
230+
pileup_track = PileupTrack(data=pileup_data) # ty:ignore[unknown-argument]
231231

232232
view = hg.view((pileup_track, "top"))
233233
uid1 = view.uid
234+
assert view.tracks.top
234235
assert view.tracks.top[0].plugin_url == some_url
235236

236237
# The .domain() function creates a copy of the view. We want to make sure
237238
# that the plugin_url attribute of the PluginTrack is maintained
238-
view = view.domain(x=[0, 10])
239+
view = view.domain(x=(0, 10))
239240
uid2 = view.uid
240241
assert view.tracks.top[0].plugin_url == some_url
241242

0 commit comments

Comments
 (0)