Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pythonapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
opt: ["codeformat", "pytype", "mypy"]
opt: ["codeformat", "pytype", "ty"]
Comment thread
garciadias marked this conversation as resolved.
Outdated
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/weekly-preview.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
opt: ["codeformat", "pytype", "mypy"]
opt: ["codeformat", "pytype", "ty"]
Comment thread
garciadias marked this conversation as resolved.
Outdated
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.9
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ examples/scd_lvsegs.npz
temp/
.idea/
.dmypy.json
.ty_cache/

*~

Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ Please note that, as per PyTorch, MONAI uses American English spelling. This mea

### Preparing pull requests
To ensure the code quality, MONAI relies on several linting tools ([flake8 and its plugins](https://gitlab.com/pycqa/flake8), [black](https://github.com/psf/black), [isort](https://github.com/timothycrosley/isort), [ruff](https://github.com/astral-sh/ruff)),
static type analysis tools ([mypy](https://github.com/python/mypy), [pytype](https://github.com/google/pytype)), as well as a set of unit/integration tests.
static type analysis tools ([ty](https://docs.astral.sh/ty/), [pytype](https://github.com/google/pytype)), as well as a set of unit/integration tests.

This section highlights all the necessary preparation steps required before sending a pull request.
To collaborate efficiently, please read through this section and follow them.
Expand Down
51 changes: 51 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,57 @@ extend-ignore = [
"NPY002", # numpy-legacy-random
]

[tool.ty]
[tool.ty.environment]
python-version = "3.9"

[tool.ty.src]
exclude = [
"**/venv/**",
"**/.venv/**",
"versioneer.py",
"monai/_version.py",
]

[tool.ty.rules]
# Only rules explicitly listed here; all unlisted rules are ignored.
# This provides a stable baseline matching mypy's output (zero diagnostics on monai/).
# Rules can be re-enabled incrementally as the codebase is improved.
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
unresolved-import = "ignore"
unused-ignore-comment = "ignore"
unused-type-ignore-comment = "ignore"
unresolved-attribute = "ignore"
unresolved-reference = "ignore"
invalid-method-override = "ignore"
invalid-argument-type = "ignore"
invalid-assignment = "ignore"
invalid-return-type = "ignore"
invalid-type-form = "ignore"
invalid-declaration = "ignore"
invalid-yield = "ignore"
call-non-callable = "ignore"
call-top-callable = "ignore"
index-out-of-bounds = "ignore"
missing-argument = "ignore"
no-matching-overload = "ignore"
not-iterable = "ignore"
not-subscriptable = "ignore"
parameter-already-assigned = "ignore"
unsupported-operator = "ignore"
deprecated = "ignore"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be ignoring this one, or does it give incorrect feedback? I'd like to minimise how many things we're ignoring so we don't hide real issues like we have in the past.

division-by-zero = "ignore"
invalid-enum-member-annotation = "ignore"
possibly-missing-attribute = "ignore"
possibly-missing-submodule = "ignore"
possibly-unresolved-reference = "ignore"
unknown-argument = "ignore"
too-many-positional-arguments = "ignore"

[[tool.ty.overrides]]
include = ["versioneer.py", "monai/_version.py"]
[tool.ty.overrides.rules]
all = "ignore"

[tool.pytype]
# Space-separated list of files or directories to exclude.
exclude = ["versioneer.py", "_version.py"]
Expand Down
2 changes: 1 addition & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ isort>=5.1, <6.0
ruff
pytype>=2020.6.1; platform_system != "Windows"
types-setuptools
mypy>=1.5.0, <1.12.0
ty
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated
ninja
torchio
torchvision
Expand Down
30 changes: 15 additions & 15 deletions runtests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ doRuffFix=false
doClangFormat=false
doCopyRight=false
doPytypeFormat=false
doMypyFormat=false
doTyFormat=false
doCleanup=false
doDistTests=false
doPrecommit=false
Expand All @@ -61,7 +61,7 @@ PY_EXE=${MONAI_PY_EXE:-$(which python)}

function print_usage {
echo "runtests.sh [--codeformat] [--autofix] [--black] [--isort] [--flake8] [--pylint] [--ruff]"
echo " [--clangformat] [--precommit] [--pytype] [-j number] [--mypy]"
echo " [--clangformat] [--precommit] [--pytype] [-j number] [--ty]"
echo " [--unittests] [--disttests] [--coverage] [--quick] [--min] [--net] [--build] [--list_tests]"
Comment on lines +64 to 65
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Keep --codeformat wired to the active type checker.

-f/--codeformat is still documented as running all style and static analysis checks, but it never sets doPyreflyFormat=true. The shorthand now skips type checking unless callers remember to add --pyrefly.

Suggested fix
         -f|--codeformat)
             doBlackFormat=true
             doIsortFormat=true
             doFlake8Format=true
             # doPylintFormat=true  # https://github.com/Project-MONAI/MONAI/issues/7094
             doRuffFormat=true
+            doPyreflyFormat=true
             doCopyRight=true
         ;;

Also applies to: 90-91, 265-272, 312-313

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@runtests.sh` around lines 65 - 66, The help and option parsing treat
-f/--codeformat as running style checks but do not enable the pyrefly/type
checker; update the option handling so that the -f|--codeformat branch sets
doPyreflyFormat=true (in addition to any existing doCodeFormat/doClangFormat
flags) and ensure the usage/help echoes (the echo lines that list options)
reflect that -f/--codeformat includes pyrefly/type checking; search for the
option parsing block that handles -f/--codeformat and the variable
doPyreflyFormat to make the change and also update the repeated help strings
mentioned (around the echoed option lists) so the documentation matches
behavior.

echo " [--dryrun] [--copyright] [--clean] [--help] [--version] [--path] [--formatfix]"
echo ""
Expand Down Expand Up @@ -89,7 +89,7 @@ function print_usage {
echo "Python type check options:"
echo " --pytype : perform \"pytype\" static type checks"
echo " -j, --jobs : number of parallel jobs to run \"pytype\" (default $NUM_PARALLEL)"
echo " --mypy : perform \"mypy\" static type checks"
echo " --ty : perform \"ty\" static type checks"
echo ""
echo "MONAI unit testing options:"
echo " -u, --unittests : perform unit testing"
Expand Down Expand Up @@ -314,8 +314,8 @@ do
--pytype)
doPytypeFormat=true
;;
--mypy)
doMypyFormat=true
--ty)
doTyFormat=true
;;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
-j|--jobs)
NUM_PARALLEL=$2
Expand Down Expand Up @@ -654,26 +654,26 @@ then
fi


if [ $doMypyFormat = true ]
if [ $doTyFormat = true ]
then
set +e # disable exit on failure so that diagnostics can be given on failure
echo "${separator}${blue}mypy${noColor}"
echo "${separator}${blue}ty${noColor}"

# ensure that the necessary packages for code format testing are installed
if ! is_pip_installed mypy
if ! is_pip_installed ty
then
install_deps
fi
${cmdPrefix}"${PY_EXE}" -m mypy --version
${cmdPrefix}"${PY_EXE}" -m mypy "$homedir"
${cmdPrefix}"${PY_EXE}" -m ty --version
${cmdPrefix}"${PY_EXE}" -m ty check "$homedir"

mypy_status=$?
if [ ${mypy_status} -ne 0 ]
ty_status=$?
if [ ${ty_status} -ne 0 ]
then
: # mypy output already follows format
exit ${mypy_status}
: # ty output already follows format
exit ${ty_status}
else
: # mypy output already follows format
: # ty output already follows format
fi
set -e # enable exit on failure
fi
Expand Down