Skip to content

Commit 2fad2e6

Browse files
Migrate from pyright to ty (#24)
* Introduce ty * Fix ty issues * Update vscode config * remove mise file
1 parent 3d6c342 commit 2fad2e6

32 files changed

Lines changed: 213 additions & 264 deletions

File tree

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ jobs:
2929
run: uv sync --all-packages --frozen
3030
- name: Ruff
3131
run: uv run ruff format --check . && uv run ruff check .
32-
- name: Pyright
33-
run: uv run pyright .
32+
- name: Ty
33+
run: uv run ty check
3434

3535
tests:
3636
name: Run tests

.pre-commit-config.yaml

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
repos:
22
- repo: https://github.com/pre-commit/pre-commit-hooks
3-
rev: v5.0.0
3+
rev: v6.0.0
44
hooks:
55
- id: check-yaml
66
- id: end-of-file-fixer
77
- repo: https://github.com/tsvikas/sync-with-uv
8-
rev: v0.4.0
8+
rev: v0.5.0
99
hooks:
1010
- id: sync-with-uv
1111
- repo: https://github.com/charliermarsh/ruff-pre-commit
@@ -14,7 +14,12 @@ repos:
1414
- id: ruff-check
1515
args: [--fix, --exit-non-zero-on-fix]
1616
- id: ruff-format
17-
- repo: https://github.com/RobertCraigie/pyright-python
18-
rev: v1.1.400
17+
- repo: local
1918
hooks:
20-
- id: pyright
19+
- id: ty-check
20+
name: ty-check
21+
language: python
22+
entry: ty check
23+
pass_filenames: false
24+
args: [--python=.venv/]
25+
additional_dependencies: [ty]

.vscode/extensions.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"recommendations": [
3+
"astral-sh.ty",
34
"ms-python.python",
45
"ms-python.vscode-pylance",
56
"charliermarsh.ruff",

.vscode/settings.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
}
1313
},
1414
"files.insertFinalNewline": true,
15+
"python.languageServer": "None",
1516
"python.testing.unittestEnabled": false,
1617
"python.testing.pytestEnabled": true,
1718
"python.analysis.autoImportCompletions": true,

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ uv run --package tilebox-datasets pytest tilebox-datasets
4242
uv run ruff format . && uv run ruff check --fix .
4343

4444
# type checking:
45-
uv run pyright .
45+
uv run ty check
4646
```
4747

4848
### Adding dependencies to one of the packages
@@ -54,8 +54,8 @@ uv add --package tilebox-datasets "numpy>=2"
5454
### Used code quality tools
5555

5656
- [ruff](https://github.com/astral-sh/ruff) for linting and formatting
57-
- [pyright](https://github.com/microsoft/pyright) for type checking
58-
- [pre-commit](https://pre-commit.com/) for running all of the above automatically on each git commit
57+
- [ty](github.com/astral-sh/ty) for type checking
58+
- [prek](https://prek.j178.dev/) for running all of the above automatically on each git commit
5959

6060
## Protobuf usage
6161

pyproject.toml

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,10 @@ dev = [
2424
"pyarrow>=17.0.0",
2525
# some dev tooling
2626
"ruff>=0.11.10",
27-
# pyright 1.1.401 reports many wrong false positives, let's wait until that is fixed before upgrading
28-
"pyright>=1.1.379,<1.1.401",
29-
"pre-commit>=3.8.0",
3027
"types-protobuf>=6.30",
3128
"junitparser>=3.2.0",
29+
"ty>=0.0.11",
30+
"prek>=0.2.27",
3231
]
3332

3433
[project.scripts]
@@ -112,33 +111,10 @@ known-first-party = ["tilebox", "_tilebox"]
112111
[tool.ruff.lint.per-file-ignores]
113112
"*/tests/*" = ["INP001", "SLF001"]
114113

115-
[tool.pyright]
114+
[tool.ty.src]
116115
exclude = [
117-
"**/.ipynb_checkpoints",
118-
"**/__pycache__",
119-
".venv",
120-
"tilebox-datasets/tests/example_dataset/*", # auto-generated code
121-
"tilebox-workflows/tests/proto/*", # auto-generated code
116+
# auto-generated code
117+
"**/*_pb2.py",
118+
"**/*_pb2.pyi",
119+
"**/*pb2_grpc.py"
122120
]
123-
124-
# ignore warnings in those files, but still type check them when used as a dependency in other files
125-
ignore = [
126-
# it's auto generated
127-
"**/datasets/v1",
128-
"**/workflows/v1",
129-
"**/tilebox/v1",
130-
"**/buf/validate",
131-
]
132-
133-
# pyright needs to have all the dependencies installed to be able to type check
134-
# we can make sure of this by telling it to use the uv venv
135-
venvPath = "."
136-
venv = ".venv"
137-
extraPaths = [
138-
"tilebox-datasets",
139-
"tilebox-grpc",
140-
"tilebox-storage",
141-
"tilebox-workflows",
142-
]
143-
144-
reportPrivateImportUsage = false

tilebox-datasets/tests/data/datapoint.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def example_datapoints(draw: DrawFn, generated_fields: bool = False, missing_fie
6262
some_time=draw(datetime_messages() | maybe_none),
6363
some_duration=draw(duration_messages() | maybe_none),
6464
some_bytes=draw(binary(min_size=1, max_size=10) | maybe_none),
65-
some_bool=draw(booleans() | maybe_none), # type: ignore[arg-type]
65+
some_bool=draw(booleans() | maybe_none),
6666
# well-known types
6767
some_identifier=draw(uuid_messages() | maybe_none),
6868
some_vec3=draw(vec3_messages() | maybe_none),

tilebox-datasets/tilebox/datasets/message_pool.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from google.protobuf import descriptor_pb2, duration_pb2, timestamp_pb2
22
from google.protobuf.descriptor_pool import Default
3+
from google.protobuf.message import Message
34
from google.protobuf.message_factory import GetMessageClass, GetMessages
45

56
from tilebox.datasets.data.datasets import AnnotatedType
@@ -25,5 +26,5 @@ def register_message_types(descriptor_set: descriptor_pb2.FileDescriptorSet) ->
2526
GetMessages(descriptor_set.file, pool=Default())
2627

2728

28-
def get_message_type(type_url: str) -> type:
29+
def get_message_type(type_url: str) -> type[Message]:
2930
return GetMessageClass(Default().FindMessageTypeByName(type_url))

tilebox-datasets/tilebox/datasets/progress.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def _calc_progress_seconds(self, time: datetime) -> int:
6262

6363
def set_progress(self, time: datetime) -> None:
6464
"""Set the progress of the progress bar to the given time"""
65-
done = min(self._calc_progress_seconds(time), self._progress_bar.total)
65+
total = self._calc_progress_seconds(self._interval.end)
66+
done = min(self._calc_progress_seconds(time), total)
6667
self._progress_bar.update(done - self._progress_bar.n)
6768

6869
def set_download_info(self, datapoints: int, byte_size: int, download_time: float) -> None:
@@ -79,7 +80,8 @@ def __exit__(
7980
) -> None:
8081
try:
8182
if traceback is None:
82-
self._progress_bar.update(self._progress_bar.total - self._progress_bar.n) # set to 100%
83+
total = self._calc_progress_seconds(self._interval.end)
84+
self._progress_bar.update(total - self._progress_bar.n) # set to 100%
8385

8486
self._progress_bar.close() # mark as completed or failed
8587
except AttributeError:

tilebox-datasets/tilebox/datasets/protobuf_conversion/field_types.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from collections.abc import Sized
1+
from collections.abc import Sequence
22
from datetime import timedelta
33
from typing import Any
44
from uuid import UUID
@@ -16,9 +16,10 @@
1616
from tilebox.datasets.datasets.v1.well_known_types_pb2 import UUID as UUIDMessage # noqa: N811
1717
from tilebox.datasets.datasets.v1.well_known_types_pb2 import Geometry, LatLon, LatLonAlt, Quaternion, Vec3
1818

19-
ProtoFieldValue = Message | float | str | bool | bytes | Sized | None
19+
ScalarProtoFieldValue = Message | float | str | bool | bytes
20+
ProtoFieldValue = ScalarProtoFieldValue | Sequence[ScalarProtoFieldValue] | None
2021

21-
_FILL_VALUES_BY_DTYPE = {
22+
_FILL_VALUES_BY_DTYPE: dict[type[np.dtype[Any]], Any] = {
2223
npdtypes.Int8DType: np.int8(0),
2324
npdtypes.Int16DType: np.int16(0),
2425
npdtypes.Int32DType: np.int32(0),

0 commit comments

Comments
 (0)