Skip to content

Commit d7098ef

Browse files
Use ty for fast type checking :-) (#900)
* fast type checking :-) * fast type checking :-) * fast type checking :-) * fast type checking :-) * Update blueprints/cli.py Co-authored-by: Copilot <[email protected]> * fast type checking :-) --------- Co-authored-by: Copilot <[email protected]>
1 parent aa0a972 commit d7098ef

File tree

40 files changed

+198
-346
lines changed

40 files changed

+198
-346
lines changed

.github/dependabot.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ updates:
1313
groups:
1414
dev-dependencies: # name of group
1515
patterns:
16-
- "mypy"
16+
- "ty"
1717
- "ruff"
1818
- "pre-commit"
1919
- "pytest"

.github/workflows/build_deploy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ jobs:
4040
- name: Run formatting checks with ruff
4141
run: make format
4242

43-
- name: Run type checks with mypy
43+
- name: Run type checks with ty
4444
run: make typecheck
4545

4646
- name: Build package

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ jobs:
4545
- name: Run formatting checks with ruff
4646
run: make format
4747

48-
- name: Run type checks with mypy
48+
- name: Run type checks with ty
4949
run: make typecheck

.gitignore

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,11 +140,6 @@ venv.bak/
140140
# mkdocs documentation
141141
/site
142142

143-
# mypy
144-
.mypy_cache/
145-
.dmypy.json
146-
dmypy.json
147-
148143
# Pyre type checker
149144
.pyre/
150145

.pre-commit-config.yaml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,5 @@ repos:
2525
# Run the formatter.
2626
- id: ruff-format
2727

28-
- repo: https://github.com/pre-commit/mirrors-mypy
29-
rev: v1.17.0
30-
hooks:
31-
- id: mypy
32-
language_version: python3.12
28+
# As of january 2026, ty does not have an official pre-commit hook.
29+
# We will add it here once it is available.

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ RUN := $(UV) run
1818
BUILD := $(UV) build
1919
PYTEST := $(RUN) $(NO_DEV) pytest
2020
COVERAGE := $(PYTEST) --cov=./blueprints
21-
MYPY := $(RUN) mypy
21+
TY := $(RUN) ty
2222
RUFF := $(RUN) ruff
2323

2424
#─────────────────────────────────────────────────────────────────────────────
@@ -55,8 +55,8 @@ format: ## Check the formatting with Ruff
5555
$(RUFF) format . --check
5656

5757
.PHONY: typecheck
58-
typecheck: ## Run static type checks with mypy
59-
$(MYPY) -p blueprints
58+
typecheck: ## Run static type checks with ty
59+
$(TY) check blueprints
6060

6161
#─────────────────────────────────────────────────────────────────────────────
6262
# Testing targets
@@ -97,5 +97,5 @@ build: ## Build the project
9797
#─────────────────────────────────────────────────────────────────────────────
9898
.PHONY: clean
9999
clean: ## Remove venv and all build/test artifacts
100-
@rm -rf .venv htmlcov .pytest_cache .mypy_cache .ruff_cache .coverage;\
100+
@rm -rf .venv htmlcov .pytest_cache .ruff_cache .coverage;\
101101
echo "Cleaned up all build/test artifacts and virtual environment"

blueprints/checks/check_result.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,12 @@ class CheckResult:
7676
is_ok: bool | None = None
7777

7878
@classmethod
79-
def from_comparison(cls, provided: float, required: float, operator: Literal["<", "<=", "==", ">=", ">", "!="] = "<=") -> Self:
79+
def from_comparison(
80+
cls,
81+
provided: float,
82+
required: float,
83+
operator: Literal["<", "<=", "==", ">=", ">", "!="] = "<=", # ty: ignore[invalid-argument-type]
84+
) -> Self:
8085
"""
8186
Create a CheckResult from a direct comparison of provided and required values.
8287
Will automatically calculate unity_check, factor_of_safety, and is_ok.

blueprints/cli.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -222,25 +222,25 @@ def formatting(ctx: typer.Context) -> None:
222222

223223
@app.command(context_settings={"allow_extra_args": True, "ignore_unknown_options": True})
224224
def typecheck(ctx: typer.Context) -> None:
225-
"""Run static type checks with mypy.
225+
"""Run static type checks with ty from astral.
226226
227-
Performs static type checking on the blueprints package using mypy.
227+
Performs static type checking on the blueprints package using ty.
228228
Equivalent to: make typecheck
229229
230230
Parameters
231231
----------
232232
ctx : typer.Context
233-
Typer context containing additional arguments to pass to mypy.
233+
Typer context containing additional arguments to pass to ty.
234234
235235
Notes
236236
-----
237-
Additional arguments are passed directly to mypy. Common examples:
238-
- `--strict` : Enable strict mode
239-
- `--ignore-missing-imports` : Ignore missing imports
240-
- `--show-error-codes` : Show error codes
237+
Additional arguments are passed directly to ty. Common examples:
238+
- `--verbose` : Increase verbosity of type checking output
239+
- `--quiet` : Reduce output to essential information
240+
- See `ty --help` for the full list of supported options
241241
"""
242-
console.print("[bold blue]Running mypy type checker...[/bold blue]")
243-
run_command(["uv", "run", "mypy", "-p", "blueprints", *ctx.args])
242+
console.print("[bold blue]Running ty type checker...[/bold blue]")
243+
run_command(["uv", "run", "ty", "check", "blueprints", *ctx.args])
244244

245245

246246
# Testing Commands
@@ -405,7 +405,7 @@ def check() -> None: # noqa: PLR0915
405405
Runs the following checks in order:
406406
1. Lint with Ruff
407407
2. Format check with Ruff
408-
3. Type checking with mypy
408+
3. Type checking with ty
409409
4. Coverage validation with pytest
410410
411411
Raises
@@ -455,9 +455,9 @@ def check() -> None: # noqa: PLR0915
455455
console.print("[bold red]Format: FAILED (Use `blueprints formatting` to auto-format files)[/bold red]")
456456

457457
# 3. Type check
458-
console.print("\n[bold blue]3. Running type checks with mypy...[/bold blue]")
458+
console.print("\n[bold blue]3. Running type checks with ty...[/bold blue]")
459459
result = subprocess.run(
460-
args=["uv", "run", "mypy", "-p", "blueprints"],
460+
args=["uv", "run", "ty", "check", "blueprints"],
461461
capture_output=False,
462462
text=True,
463463
check=False,

blueprints/codes/eurocode/en_1992_1_1_2004/chapter_4_durability_and_cover/table_4_1.py

Lines changed: 26 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
according to Table 4.1 from EN 1992-1-1:2004: Chapter 4 - Durability and cover to reinforcement.
33
"""
44

5+
from dataclasses import dataclass, field
56
from functools import total_ordering
67

78
from blueprints.codes.eurocode.en_1992_1_1_2004.chapter_4_durability_and_cover._base_classes.exposure_classes import (
@@ -211,36 +212,29 @@ def description_of_the_environment(self) -> str:
211212
return "Not applicable"
212213

213214

215+
@dataclass(frozen=True)
214216
class Table4Dot1ExposureClasses(ExposureClassesBase):
215-
"""Class representing table 4.1 from EN 1992-1-1:2004."""
216-
217-
def __init__(
218-
self,
219-
carbonation: Carbonation = Carbonation.NA,
220-
chloride: Chloride = Chloride.NA,
221-
chloride_seawater: ChlorideSeawater = ChlorideSeawater.NA,
222-
freeze_thaw: FreezeThaw = FreezeThaw.NA,
223-
chemical: Chemical = Chemical.NA,
224-
) -> None:
225-
"""Implementation of table 4.1 from EN 1992-1-1:2004 par. 4.2.
226-
227-
Exposure classes related to environmental conditions in accordance with EN 206-1
228-
229-
Parameters
230-
----------
231-
carbonation : Carbonation
232-
The carbonation exposure class. Defaults to Carbonation.NA.
233-
chloride : Chloride
234-
The chloride exposure class. Defaults to Chloride.NA.
235-
chloride_seawater : ChlorideSeawater
236-
The chloride seawater exposure class. Defaults to ChlorideSeawater.NA.
237-
freeze_thaw : FreezeThaw
238-
The freeze/thaw exposure class. Defaults to FreezeThaw.NA.
239-
chemical : Chemical
240-
The chemical exposure class. Defaults to Chemical.NA.
241-
"""
242-
self.carbonation = carbonation
243-
self.chloride = chloride
244-
self.chloride_seawater = chloride_seawater
245-
self.freeze_thaw = freeze_thaw
246-
self.chemical = chemical
217+
"""Class representing table 4.1 from EN 1992-1-1:2004.
218+
219+
Exposure classes related to environmental conditions in accordance with EN 206-1
220+
221+
Arguments
222+
---------
223+
carbonation : Carbonation
224+
The carbonation exposure class. Defaults to Carbonation.NA.
225+
chloride : Chloride
226+
The chloride exposure class. Defaults to Chloride.NA.
227+
chloride_seawater : ChlorideSeawater
228+
The chloride seawater exposure class. Defaults to ChlorideSeawater.NA.
229+
freeze_thaw : FreezeThaw
230+
The freeze/thaw exposure class. Defaults to FreezeThaw.NA.
231+
chemical : Chemical
232+
The chemical exposure class. Defaults to Chemical.NA.
233+
234+
"""
235+
236+
carbonation: Carbonation = field(default=Carbonation.NA)
237+
chloride: Chloride = field(default=Chloride.NA)
238+
chloride_seawater: ChlorideSeawater = field(default=ChlorideSeawater.NA)
239+
freeze_thaw: FreezeThaw = field(default=FreezeThaw.NA)
240+
chemical: Chemical = field(default=Chemical.NA)

blueprints/codes/eurocode/en_1992_1_1_2004/chapter_4_durability_and_cover/table_4_4n.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ def __init__(
3434
The structural class of the concrete. Use the [$Table4Dot3ConcreteStructuralClass$] class. [$-$]
3535
"""
3636
super().__init__()
37-
self.exposure_classes = exposure_classes
38-
self.structural_class = structural_class
37+
self.exposure_classes: Table4Dot1ExposureClasses = exposure_classes
38+
self.structural_class: ConcreteStructuralClassBase = structural_class
3939

4040
@staticmethod
4141
def _evaluate(

0 commit comments

Comments
 (0)