diff --git a/docs/source/changes.md b/docs/source/changes.md index 499dcb9..6089f73 100644 --- a/docs/source/changes.md +++ b/docs/source/changes.md @@ -6,8 +6,9 @@ them in reverse chronological order. ## Unreleased - {pull}`70` drops support for Python 3.9 and adds support for Python 3.14. -- {pull}`73` removes tox in favor of uv + just. +- {pull}`71` switches typing from mypy to ty. - {pull}`72` updates the pre-commit hooks. +- {pull}`73` removes tox in favor of uv + just. ## 1.8.0 - 2024-12-24 diff --git a/justfile b/justfile index 3f9d56b..e9bd3a1 100644 --- a/justfile +++ b/justfile @@ -12,7 +12,7 @@ test-cov: # Run type checking typing: - uv run --extra typing --extra test mypy + uv run --extra typing --extra test ty check hooks/ tests/ # Run linting and formatting lint: diff --git a/pyproject.toml b/pyproject.toml index 88b5ae9..5904a44 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -36,7 +36,7 @@ docs = [ "sphinxext-opengraph", ] test = ["pytest", "pytest-cookies", "pytest-cov"] -typing = ["mypy"] +typing = ["ty>=0.0.7"] [project.readme] file = "README.md" @@ -52,21 +52,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] fix = true 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/tests/test_cookie.py b/tests/test_cookie.py index ce41702..723cc7f 100644 --- a/tests/test_cookie.py +++ b/tests/test_cookie.py @@ -90,20 +90,20 @@ def test_check_pixi_and_run_all_checks(cookies): check=True, ) - # Install pre-commit. + # 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, ) diff --git a/{{cookiecutter.project_slug}}/pyproject.toml b/{{cookiecutter.project_slug}}/pyproject.toml index 793f5ec..1e95f19 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}}/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" 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."""