Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
22 changes: 22 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,28 @@ 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]
unresolved-import = "ignore"
unused-ignore-comment = "ignore"
unused-type-ignore-comment = "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
50 changes: 0 additions & 50 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -225,56 +225,6 @@ versionfile_build = monai/_version.py
tag_prefix =
parentdir_prefix =

[mypy]
# Suppresses error messages about imports that cannot be resolved.
ignore_missing_imports = True
# Changes the treatment of arguments with a default value of None by not implicitly making their type Optional.
no_implicit_optional = True
# Warns about casting an expression to its inferred type.
warn_redundant_casts = True
# No error on unneeded # type: ignore comments.
warn_unused_ignores = False
# Shows a warning when returning a value with type Any from a function declared with a non-Any return type.
warn_return_any = True
# Prohibit equality checks, identity checks, and container checks between non-overlapping types.
strict_equality = True
# Shows column numbers in error messages.
show_column_numbers = True
# Shows error codes in error messages.
show_error_codes = True
# Use visually nicer output in error messages: use soft word wrap, show source code snippets, and show error location markers.
pretty = False
# Warns about per-module sections in the config file that do not match any files processed when invoking mypy.
warn_unused_configs = True
# Make arguments prepended via Concatenate be truly positional-only.
extra_checks = True
# Allows variables to be redefined with an arbitrary type,
# as long as the redefinition is in the same block and nesting level as the original definition.
# allow_redefinition = True

exclude = venv/

[mypy-versioneer]
# Ignores all non-fatal errors.
ignore_errors = True

[mypy-monai._version]
# Ignores all non-fatal errors.
ignore_errors = True

[mypy-monai.eggs]
# Ignores all non-fatal errors.
ignore_errors = True

[mypy-monai.*]
# Also check the body of functions with no types in their type signature.
check_untyped_defs = True
# Warns about usage of untyped decorators.
disallow_untyped_decorators = True

[mypy-monai.visualize.*,monai.utils.*,monai.optimizers.*,monai.losses.*,monai.inferers.*,monai.config.*,monai._extensions.*,monai.fl.*,monai.engines.*,monai.handlers.*,monai.auto3dseg.*,monai.bundle.*,monai.metrics.*,monai.apps.*]
disallow_incomplete_defs = True

[coverage:run]
concurrency = multiprocessing
source = .
Expand Down