Skip to content

Commit f42a641

Browse files
committed
Switch to ty for type checking
1 parent a81bb20 commit f42a641

File tree

24 files changed

+141
-142
lines changed

24 files changed

+141
-142
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,9 @@ jobs:
3636
uses: actions/setup-python@v6
3737
with:
3838
python-version-file: pyproject.toml
39-
- name: Check types with mypy
39+
- name: Check types with ty
4040
run: |
41-
uv add pip
42-
uv run mypy --install-types --non-interactive
43-
uv run mypy
41+
uv run ty check
4442
4543
test:
4644
runs-on: ubuntu-22.04

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pytest
6464
Type check the code with:
6565

6666
```bash
67-
mypy
67+
ty check
6868
```
6969

7070
### Linting

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
[![Documentation](https://img.shields.io/readthedocs/foamlib)](https://foamlib.readthedocs.io/)
44
[![CI](https://github.com/gerlero/foamlib/actions/workflows/ci.yml/badge.svg)](https://github.com/gerlero/foamlib/actions/workflows/ci.yml)
55
[![Codecov](https://codecov.io/gh/gerlero/foamlib/branch/main/graph/badge.svg)](https://codecov.io/gh/gerlero/foamlib)
6-
[![Checked with mypy](http://www.mypy-lang.org/static/mypy_badge.svg)](http://mypy-lang.org/)
76
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
7+
[![ty](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ty/main/assets/badge/v0.json)](https://github.com/astral-sh/ty)
88
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
99
[![Publish](https://github.com/gerlero/foamlib/actions/workflows/pypi-publish.yml/badge.svg)](https://github.com/gerlero/foamlib/actions/workflows/pypi-publish.yml)
1010
[![PyPI](https://img.shields.io/pypi/v/foamlib)](https://pypi.org/project/foamlib/)

examples/basic/diffusioncheck.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136
y = y[end]
137137
z = z[end]
138138

139-
DT = case.transport_properties["DT"].value
139+
DT = case.transport_properties["DT"].value # ty: ignore[possibly-unbound-attribute]
140140
U = case[0]["U"].internal_field[0]
141141

142142
for time in case[1:]:

examples/parametricStudy/createStudyGrid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from foamlib.preprocessing.grid_parameter_sweep import CaseParameter, GridParameter
44
from foamlib.preprocessing.of_dict import FoamDictInstruction
55
from foamlib.preprocessing.parameter_study import grid_generator
6-
from foamlib.preprocessing.system import simulationParameters
6+
from foamlib.preprocessing.system import simulation_parameters
77

88
# damBreak
99
root = Path(__file__).parent
@@ -28,7 +28,7 @@ def grid_parameters(scale) -> list[int]:
2828
# file_name=Path("system/simulationParameters"),
2929
# keys=[f"res{i}"],
3030
# )
31-
modify_dict=[simulationParameters(keys=[f"res{i}"]) for i in range(1, 6)],
31+
modify_dict=[simulation_parameters(keys=[f"res{i}"]) for i in range(1, 6)],
3232
parameters=[
3333
CaseParameter(name="coarse", values=grid_parameters(1)),
3434
CaseParameter(name="mid", values=grid_parameters(2)),
@@ -38,7 +38,7 @@ def grid_parameters(scale) -> list[int]:
3838

3939
init_height = GridParameter(
4040
parameter_name="initHeight",
41-
modify_dict=[simulationParameters(keys=["initHeight"])],
41+
modify_dict=[simulation_parameters(keys=["initHeight"])],
4242
parameters=[
4343
CaseParameter(name="height_02", values=[0.2]),
4444
CaseParameter(name="height_03", values=[0.3]),

examples/parametricStudy/gatherResults.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
out_files = list_function_objects(root / "Cases")
1616

1717

18-
def max_height_filter(table: pd.DataFrame, parameters: dict[str, str]) -> pd.DataFrame:
18+
def max_height_filter(table: pd.DataFrame, parameters: list[dict[str, str]]) -> pd.DataFrame:
1919
"""Filter the table to get the maximum height."""
2020
d = {
2121
"x": [table["x"].max()],
@@ -31,21 +31,24 @@ def max_height_filter(table: pd.DataFrame, parameters: dict[str, str]) -> pd.Dat
3131
source=out_files["forces--force.dat"], dir_name=root / "Cases"
3232
)
3333
# %%
34+
assert forces is not None
3435
forces.to_csv(
3536
results / "forces.csv",
3637
index=False,
3738
)
3839

3940
probe_u = load_tables(source=out_files["probes--U"], dir_name=root / "Cases")
41+
assert probe_u is not None
4042
probe_u.to_csv(
4143
results / "probe_u.csv",
4244
index=False,
4345
)
4446

45-
file = DataSource(file_name="U_freeSurface.raw", folder="freeSurface")
47+
file = DataSource(file_name="U_freeSurface.raw", folder="freeSurface") # ty: ignore[missing-argument]
4648
surface_heights = load_tables(
4749
source=file, dir_name=root / "Cases", filter_table=max_height_filter
4850
)
51+
assert surface_heights is not None
4952
surface_heights.to_csv(
5053
results / "surface_heights.csv",
5154
index=False,

foamlib/_cases/_subprocess.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,9 @@ def run_sync(
103103
timeout=0.1
104104
): # Small timeout to allow log monitoring
105105
assert key.fileobj in open_streams
106-
if not (line := key.fileobj.readline()): # type: ignore [union-attr]
106+
if not (line := key.fileobj.readline()):
107107
selector.unregister(key.fileobj)
108-
open_streams.remove(key.fileobj) # type: ignore [arg-type]
108+
open_streams.remove(key.fileobj)
109109
elif key.fileobj is proc.stdout:
110110
process_stdout(line)
111111
if output is not None:

foamlib/_cases/async_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ async def _run(
150150
async def _rmtree(
151151
path: os.PathLike[str] | str, *, ignore_errors: bool = False
152152
) -> None:
153-
await aioshutil.rmtree(path, ignore_errors=ignore_errors) # type: ignore [call-arg]
153+
await aioshutil.rmtree(path, ignore_errors=ignore_errors)
154154

155155
@override
156156
@staticmethod

foamlib/_files/_parsing/parsed.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def put(
121121
self._remove_child_entries(keywords)
122122

123123
@override
124-
def add( # type: ignore[override]
124+
def add(
125125
self,
126126
keywords: tuple[str, ...],
127127
data: Data | StandaloneData | EllipsisType,

foamlib/_files/_serialization.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,10 @@ def normalize(
5656
bool_ok: bool = True,
5757
) -> Data | StandaloneData | SubDict:
5858
if isinstance(data, Mapping):
59-
items = ((normalize(k, bool_ok=False), normalize(v)) for k, v in data.items()) # type: ignore [arg-type, misc]
59+
items = ((normalize(k, bool_ok=False), normalize(v)) for k, v in data.items())
6060
if keywords is None:
61-
return as_dict_check_unique(items) # type: ignore [arg-type]
62-
ret1: SubDict = MultiDict(items) # type: ignore [arg-type]
61+
return as_dict_check_unique(items)
62+
ret1: SubDict = MultiDict(items)
6363
seen = set()
6464
for k, v in ret1.items():
6565
if k.startswith("#"):
@@ -112,7 +112,7 @@ def normalize(
112112
if arr.ndim == 1 or (arr.ndim == 2 and arr.shape[1] in (3, 6, 9)):
113113
return arr
114114

115-
return [normalize(d) for d in data] # type: ignore [arg-type, return-value]
115+
return [normalize(d) for d in data]
116116

117117
if isinstance(data, int):
118118
return float(data)
@@ -122,7 +122,7 @@ def normalize(
122122
if isinstance(data, np.ndarray):
123123
ret2 = data.tolist()
124124
assert isinstance(ret2, (int, float, list))
125-
return ret2 # type: ignore [return-value]
125+
return ret2
126126

127127
if (
128128
not isinstance(data, DimensionSet)
@@ -139,19 +139,19 @@ def normalize(
139139
if isinstance(k2, Mapping):
140140
msg = "Keyword in keyword entry cannot be a dictionary"
141141
raise ValueError(msg)
142-
k2 = normalize(k2, bool_ok=False) # type: ignore [arg-type]
143-
v2 = normalize(v2) # type: ignore [arg-type]
144-
return (k2, v2) # type: ignore [return-value]
142+
k2 = normalize(k2, bool_ok=False)
143+
v2 = normalize(v2)
144+
return (k2, v2)
145145

146146
if (
147147
is_sequence(data)
148148
and not isinstance(data, DimensionSet)
149149
and not isinstance(data, tuple)
150150
):
151-
return [normalize(d) for d in data] # type: ignore [arg-type, return-value]
151+
return [normalize(d) for d in data]
152152

153153
if isinstance(data, tuple) and not isinstance(data, DimensionSet):
154-
return tuple(normalize(d, keywords=keywords) for d in data) # type: ignore [misc]
154+
return tuple(normalize(d, keywords=keywords) for d in data)
155155

156156
if isinstance(data, str):
157157
with contextlib.suppress(ValueError, KeyError):
@@ -178,7 +178,7 @@ def dumps(
178178
header: SubDictLike | None = None,
179179
tuple_is_keyword_entry: bool = False,
180180
) -> bytes:
181-
data = normalize(data, keywords=keywords) # type: ignore [arg-type, misc]
181+
data = normalize(data, keywords=keywords)
182182

183183
if isinstance(data, Mapping):
184184
return (
@@ -287,7 +287,7 @@ def dumps(
287287

288288
if is_sequence(data):
289289
return (
290-
b"(" + b" ".join(dumps(v, tuple_is_keyword_entry=True) for v in data) + b")" # type: ignore [arg-type]
290+
b"(" + b" ".join(dumps(v, tuple_is_keyword_entry=True) for v in data) + b")"
291291
)
292292

293293
if data is True:

0 commit comments

Comments
 (0)