Title: refactor: replace mypy with ty for static type checking by bearomorphism · Pull Request #1932 · commitizen-tools/commitizen · GitHub
Open Graph Title: refactor: replace mypy with ty for static type checking by bearomorphism · Pull Request #1932 · commitizen-tools/commitizen
X Title: refactor: replace mypy with ty for static type checking by bearomorphism · Pull Request #1932 · commitizen-tools/commitizen
Description: Switch the linters group and poe lint from mypy to Astral ty, add [tool.ty] configuration, and adjust code and tests for ty semantics. Made-with: Cursor, GitHub Copilot CLI Description Replace mypy with ty (Astral's Python type checker) for static type checking. ty is significantly faster and integrates well with the existing ruff toolchain. Key changes Replace mypy with ty in the linters dependency group and poe lint task Add [tool.ty] configuration in pyproject.toml Bump ty minimum to >=0.0.33 to leverage declared-type preference (removes unnecessary cast() workarounds) Remove cast() calls where ty 0.0.33 can infer types from annotated assignments Adjust # type: ignore comments to use bare form (ty doesn't support mypy-specific error codes like [arg-type]) Update AGENTS.md references from mypy to ty Why each change is necessary All changes in this PR are required for ty compatibility — no cosmetic-only changes: File(s) Change Reason pyproject.toml Replace mypy with ty, add [tool.ty] config, bump to >=0.0.33 Core migration commitizen/commands/bump.py Remove 2 cast() calls, add TODO on remaining ty 0.0.33 declared-type preference makes them unnecessary commitizen/commands/changelog.py Replace cast() with annotated assignment ty 0.0.33 declared-type preference commitizen/version_schemes.py Replace cast() with annotated assignment, update comment ty 0.0.33 declared-type preference; "mypy check" → "static type checking" scripts/gen_cli_help_screenshots.py Replace 2 cast() calls with annotated assignments ty 0.0.33 declared-type preference commitizen/changelog_formats/__init__.py Refactor name and X or Y to explicit if/else; rename format → format_cls ty can't narrow the short-circuit and/or pattern; avoids shadowing Python builtin commitizen/changelog.py Add isinstance(msg, dict) guard ty requires explicit narrowing for dict type in mixed-type iteration commitizen/cz/customize/customize.py Reformat multiline to separate # type: ignore from # pragma: no cover ty doesn't support [no-any-return] error code commitizen/providers/*.py Change # type: ignore[index] → # type: ignore # noqa: PGH003; rename pyproject → document in poetry_provider to match parent class ty doesn't support mypy error codes; consistency with base_provider.py commitizen/cli.py, commitizen/git.py, commitizen/config/*.py, commitizen/cz/** Adjust # type: ignore comments ty uses bare # type: ignore (no mypy-specific codes) tests/test_cli.py Change "" → None in commitizen_excepthook() calls ty correctly catches "" is not TracebackType | None tests/test_cz_search_filter.py Change path="not_exist.toml" → path=Path("not_exist.toml") ty correctly catches string is not Path tests/test_changelog.py Add cast() for release["changes"] lookups, add test for non-dict skip Fix 4 pre-existing diagnostics; cover isinstance guard added for ty tests/commands/test_version_command.py Fix # type: ignore[arg-type] → bare form, remove orphaned TYPE_CHECKING ty syntax compatibility docs/contributing/contributing_tldr.md Update mypy references to ty Documentation accuracy AGENTS.md Update 3 mypy references to ty Project guidelines accuracy Checklist I have read the contributing guidelines Was generative AI tooling used to co-author this PR? Yes — Cursor, GitHub Copilot CLI Code Changes Run uv run poe all locally to ensure this change passes linter check and tests Manually test the changes: Verify uv run ty check passes with zero diagnostics Verify uv run ruff check passes Ensure backward compatibility is maintained (no runtime behavior changes — casts are no-ops, test fixes are type-correct) Update the documentation for the changes (docs/contributing/contributing_tldr.md, AGENTS.md) Expected Behavior uv run poe lint runs ruff check + ty check instead of ruff check + mypy uv run ty check reports zero diagnostics All existing tests continue to pass unchanged No runtime behavior changes (type annotations and casts are purely static; test argument fixes pass correct types) Steps to Test This Pull Request uv sync --group linters uv run ty check — should report zero diagnostics uv run ruff check — should pass uv run poe test — all tests pass Additional Context ty 0.0.33 (released April 28, 2026) introduced a "declared-type preference" feature that allows removing cast() workarounds where the RHS returns Any/Unknown but an annotation is present. Remaining casts are for cases ty genuinely cannot infer: protocol conformance (VersionScheme), TypedDict construction from spread dicts, and union narrowing in loops. One TODO remains in commitizen/commands/bump.py for a cast that can be removed once self.file_name is narrowed to str (currently str | None).
Open Graph Description: Switch the linters group and poe lint from mypy to Astral ty, add [tool.ty] configuration, and adjust code and tests for ty semantics. Made-with: Cursor, GitHub Copilot CLI Description Replace mypy...
X Description: Switch the linters group and poe lint from mypy to Astral ty, add [tool.ty] configuration, and adjust code and tests for ty semantics. Made-with: Cursor, GitHub Copilot CLI Description Replace mypy...
Opengraph URL: https://github.com/commitizen-tools/commitizen/pull/1932
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:cfd5855c-2894-dcdb-7f99-36d1de61d909 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | 93AA:27055E:D27903:11DB8FC:6A62C778 |
| html-safe-nonce | 0c12fdd5050f55e6056a2d8b9fa695bf59e97011a6117f8a1e0f3d060c4cb15b |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0FBOjI3MDU1RTpEMjc5MDM6MTFEQjhGQzo2QTYyQzc3OCIsInZpc2l0b3JfaWQiOiI0MjczOTc0ODM3NjcxODA2ODQwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 4f9d32909adea1bd6893d6070bffa93aa30fcd1d69aad8eb5f52bbf659014155 |
| hovercard-subject-tag | pull_request:3519438555 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/commitizen-tools/commitizen/pull/1932/files |
| twitter:image | https://avatars.githubusercontent.com/u/26526132?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/26526132?s=400&v=4 |
| og:image:alt | Switch the linters group and poe lint from mypy to Astral ty, add [tool.ty] configuration, and adjust code and tests for ty semantics. Made-with: Cursor, GitHub Copilot CLI Description Replace mypy... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | df33b1b61ee7b9a0af988199bfc3503c9c1acafb1f1d40e1f140ea7c84f890dd |
| turbo-cache-control | no-preview |
| diff-view | unified |
| go-import | github.com/commitizen-tools/commitizen git https://github.com/commitizen-tools/commitizen.git |
| octolytics-dimension-user_id | 62252524 |
| octolytics-dimension-user_login | commitizen-tools |
| octolytics-dimension-repository_id | 106127589 |
| octolytics-dimension-repository_nwo | commitizen-tools/commitizen |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 106127589 |
| octolytics-dimension-repository_network_root_nwo | commitizen-tools/commitizen |
| turbo-body-classes | logged-out env-production page-responsive full-width |
| disable-turbo | true |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | d41cd1bdb290013455c0ac430fa755621733f5eb |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width