-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: replace mypy with ty for static type analysis #8868
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
garciadias
wants to merge
10
commits into
Project-MONAI:dev
Choose a base branch
from
garciadias:1760-replace-mypy-with-ty-type-checker
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+87
−5
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
ba56a6d
Move test_image_filter.py
garciadias 5216b7a
Merge remote-tracking branch 'origin/dev' into dev
garciadias eacd783
Merge remote-tracking branch 'origin/dev' into dev
garciadias c64825f
Merge remote-tracking branch 'upstream/dev' into dev
garciadias 66b6c17
Merge remote-tracking branch 'origin/dev' into dev
garciadias 19cab57
Merge remote-tracking branch 'upstream/dev' into dev
garciadias 4b8086b
feat: replace mypy with ty for static type analysis
garciadias 763b7ff
fix: restore mypy config and tune ty to match zero-error baseline
garciadias ae31bb2
chore: pin ty dev dependency to ty>=0.0.38
garciadias 42ec9b2
fix: restore --mypy flag alongside --ty in runtests.sh
garciadias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -116,6 +116,7 @@ examples/scd_lvsegs.npz | |
| temp/ | ||
| .idea/ | ||
| .dmypy.json | ||
| .ty_cache/ | ||
|
|
||
| *~ | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🌐 Web query:
What is the default behavior of ty type checker for unlisted rules in tool.ty.rules configuration?💡 Result:
Default behavior: if you configure
[tool.ty.rules]without setting a particular rule, ty does not automatically invent a severity for it; instead, each rule uses ty’s built-in default level (per-rule default). The only “fallback” supported by the global config is settingall(e.g.all = "error") to apply the same severity to every rule that doesn’t have an explicit entry intool.ty.rules. [1][2] What this means for “unlisted rules”: - Unlisted rule name in[tool.ty.rules]⇒ it keeps its per-rule default level (notignore/warn/errorfrom the config), unless you setallin the same config. [1][2] - Unrecognized rule names in the config are treated separately from rule severity defaults (ty has a ruleignore-comment-unknown-rulethat warns when a# ty: ignore[...]references an unknown rule). [3] Evidence examples from docs: -tool.ty.ruleskeys are either a specific rule name orallto set a default severity for all rules. [1][2] - Rule levels areerror,warn,ignore, andall = "error"is documented as equivalent toty check --error all. [2]Citations:
🏁 Script executed:
Repository: Project-MONAI/MONAI
Length of output: 104
🏁 Script executed:
Repository: Project-MONAI/MONAI
Length of output: 237
🏁 Script executed:
Repository: Project-MONAI/MONAI
Length of output: 3829
🌐 Web query:
ty configuration [tool.ty.rules] unlisted rules ignored all fallback per-rule default wording💡 Result:
In ty, per-rule configuration works by merging configured rule severities from global rules ([tool.ty.rules] / [rules]) and then applying overrides; later overrides take precedence, and override rules “will be merged with the global rules” ([1], [2]). There’s no statement in the official configuration docs that “unlisted rules are ignored” or that fallback “per-rule default wording” is skipped when [tool.ty.rules] contains an incomplete set; instead, the documented model is that you can specify only the rules you care about, and the rest follow their normal configured defaults unless you disable them globally (for example via all = “ignore”) or enable/disable via CLI flags like --warn/--error/--ignore [1]. Your quoted behavior is more likely to be explained by how ty treats “type: ignore” codes vs “ty: ignore” codes, which can appear as “unlisted rules ignored” in practice. ty’s configuration includes respect-type-ignore-comments (default true): when false, ty treats type: ignore as a normal comment and “can’t be used to suppress ty errors” (you must use ty: ignore instead) [1]. Separately, ty has a rule ignore-comment-unknown-rule that warns when you use ty: ignore[code] or type: ignore[ty:code] with a code that isn’t a known lint rule, i.e., unrecognized codes in ignore comments won’t suppress anything and are likely a mistake [3]. So, based on the current official docs: (1) [tool.ty.rules] doesn’t imply that unlisted rules are ignored; it only sets severities for the rules you name, while other rules use their normal defaults unless you change them globally; and (2) apparent “ignoring fallback/default wording” is commonly due to suppression behavior (especially around type: ignore vs ty: ignore, and unknown ignore codes) rather than a bug in configuration merging [1][3].
Citations:
Fix misleading
tool.ty.rulescomment about “unlisted rules are ignored” in pyproject.tomlThe comment at lines 68-70 is inaccurate:
[tool.ty.rules]only sets severities for the named rules, while rules not listed there follow their normal defaults;all = "ignore"exists only under[tool.ty.overrides.rules](for versioneer.py / monai/_version.py), not for the whole project.🤖 Prompt for AI Agents