From 48b5b96d73ebb271def91984dfe14e50528517d7 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Mon, 29 Dec 2025 22:38:21 +0100 Subject: [PATCH 1/4] switch typing from mypy to ty --- docs/source/changes.md | 4 ++++ pyproject.toml | 20 ++++------------ tests/__init__.py | 2 +- tox.ini | 4 ++-- {{cookiecutter.project_slug}}/pyproject.toml | 24 ++++++------------- .../tests/__init__.py | 2 +- 6 files changed, 20 insertions(+), 36 deletions(-) diff --git a/docs/source/changes.md b/docs/source/changes.md index 106f46b..bfcc1fa 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -3,6 +3,10 @@ This is a record of all past cookiecutter-pytask-project releases and what went into them in reverse chronological order. +## Unreleased + +- {pull}`XX` switches typing from mypy to ty. + ## 1.8.0 - 2024-12-24 - {pull}`52` updates the template in many different ways. Better pre-commit hooks, diff --git a/pyproject.toml b/pyproject.toml index f44a38b..48da74e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -39,7 +39,7 @@ docs = [ "sphinxext-opengraph", ] test = ["pytest", "pytest-cookies", "pytest-cov"] -typing = ["mypy"] +typing = ["ty>=0.0.7"] [project.readme] file = "README.md" @@ -55,21 +55,11 @@ Documentation = "https://cookiecutter-pytask-project.readthedocs.io/en/latest" Github = "https://github.com/pytask-dev/cookiecutter-pytask-project" Tracker = "https://github.com/pytask-dev/cookiecutter-pytask-project/issues" -[tool.mypy] -files = ["hooks", "tests"] -exclude = "{{cookiecutter.project_slug}}" -check_untyped_defs = true -disallow_any_generics = true -disallow_incomplete_defs = true -disallow_untyped_defs = true -no_implicit_optional = true -warn_redundant_casts = true -warn_unused_ignores = true +[tool.ty.rules] +unused-ignore-comment = "error" -[[tool.mypy.overrides]] -module = "tests.*" -disallow_untyped_defs = false -ignore_errors = true +[tool.ty.terminal] +error-on-warning = true [tool.ruff] target-version = "py39" diff --git a/tests/__init__.py b/tests/__init__.py index 4045499..e24da9d 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -1 +1 @@ -"""This module is necessary to configure mypy's behavior for the tests.""" +"""Mark tests as a package for type checking.""" diff --git a/tox.ini b/tox.ini index 49f3e59..9e16ed7 100644 --- a/tox.ini +++ b/tox.ini @@ -13,8 +13,8 @@ commands = - sphinx-build -n -T -b doctest -d {envtmpdir}/doctrees docs/source docs/build/html [testenv:typing] -extras = typing -commands = mypy +extras = typing, test +commands = ty check hooks/ tests/ [testenv:test] extras = test diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index adbe51d..68cfa14 100644 --- a/{{cookiecutter.project_slug}}/pyproject.toml +++ b/{{cookiecutter.project_slug}}/pyproject.toml @@ -69,10 +69,10 @@ pytest-cov = "*" pytest-xdist = "*" [tool.pixi.feature.typing.tasks] -typing = "mypy" +typing = "ty check src/ tests/" [tool.pixi.feature.typing.dependencies] -mypy = "*" +ty = ">=0.0.7" [tool.pixi.feature.dev.tasks] nb = "jupyter lab --no-browser" @@ -87,21 +87,11 @@ docs = { features = ["docs"], solve-group = "default" } repro = { features = [], solve-group = "default" } typing = { features = ["typing"], solve-group = "default" } -[tool.mypy] -files = ["src", "tests"] -check_untyped_defs = true -disallow_any_generics = true -disallow_incomplete_defs = true -disallow_untyped_defs = true -no_implicit_optional = true -warn_redundant_casts = true -warn_unused_ignores = true -ignore_missing_imports = true - -[[tool.mypy.overrides]] -module = "tests.*" -ignore_errors = true -disallow_untyped_defs = false +[tool.ty.rules] +unused-ignore-comment = "error" + +[tool.ty.terminal] +error-on-warning = true [tool.pytask.ini_options] paths = ["src/{{ cookiecutter.project_slug }}"] diff --git a/{{cookiecutter.project_slug}}/tests/__init__.py b/{{cookiecutter.project_slug}}/tests/__init__.py index c3dc044..e24da9d 100644 --- a/{{cookiecutter.project_slug}}/tests/__init__.py +++ b/{{cookiecutter.project_slug}}/tests/__init__.py @@ -1 +1 @@ -"""Is module is necessary to configure mypy's behavior for the tests.""" +"""Mark tests as a package for type checking.""" From 200e37fea8d85a73a7e6eb052f04636991d8a567 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Mon, 29 Dec 2025 22:38:45 +0100 Subject: [PATCH 2/4] docs: update changelog for typing migration --- docs/source/changes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/source/changes.md b/docs/source/changes.md index bfcc1fa..ee17f08 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -5,7 +5,7 @@ them in reverse chronological order. ## Unreleased -- {pull}`XX` switches typing from mypy to ty. +- {pull}`71` switches typing from mypy to ty. ## 1.8.0 - 2024-12-24 From cad923e73cf5a75ac7f78f992dcb29603521d42f Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 30 Dec 2025 09:41:55 +0100 Subject: [PATCH 3/4] Fix. --- tests/test_cookie.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/test_cookie.py b/tests/test_cookie.py index ce41702..7fbe345 100644 --- a/tests/test_cookie.py +++ b/tests/test_cookie.py @@ -90,20 +90,23 @@ def test_check_pixi_and_run_all_checks(cookies): check=True, ) - # Install pre-commit. + # Install project dependencies. + subprocess.run(("pixi", "install"), cwd=result.project_path, check=True) + + # Install prek. subprocess.run( - ("pixi", "global", "install", "pre-commit"), + ("pixi", "global", "install", "prek"), cwd=result.project_path, check=True, ) # Check linting, but not on the first try since formatters fix stuff. subprocess.run( - ("pixi", "run", "pre-commit", "run", "--all-files"), + ("pixi", "run", "prek", "run", "--all-files"), cwd=result.project_path, check=False, ) subprocess.run( - ("pixi", "run", "pre-commit", "run", "--all-files"), + ("pixi", "run", "prek", "run", "--all-files"), cwd=result.project_path, check=True, ) From bb4503992a185b552ce793d21d82f9919effc4d8 Mon Sep 17 00:00:00 2001 From: Tobias Raabe Date: Tue, 30 Dec 2025 09:50:28 +0100 Subject: [PATCH 4/4] Fix. --- tests/test_cookie.py | 3 --- .../src/{{cookiecutter.project_slug}}/__init__.py | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/test_cookie.py b/tests/test_cookie.py index 7fbe345..723cc7f 100644 --- a/tests/test_cookie.py +++ b/tests/test_cookie.py @@ -90,9 +90,6 @@ def test_check_pixi_and_run_all_checks(cookies): check=True, ) - # Install project dependencies. - subprocess.run(("pixi", "install"), cwd=result.project_path, check=True) - # Install prek. subprocess.run( ("pixi", "global", "install", "prek"), diff --git a/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/__init__.py b/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/__init__.py index f2a52c2..75190c8 100644 --- a/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/__init__.py +++ b/{{cookiecutter.project_slug}}/src/{{cookiecutter.project_slug}}/__init__.py @@ -4,7 +4,7 @@ # when the project is installed with ``pip install -e .``. Do not put it into version # control! try: - from ._version import version as __version__ + from ._version import version as __version__ # ty: ignore[unresolved-import] except ImportError: __version__ = "unknown"