Skip to content

mypy: enable check-untyped-defs#35639

Draft
tgamblin wants to merge 6 commits intodevelopfrom
mypy-check-untyped-defs
Draft

mypy: enable check-untyped-defs#35639
tgamblin wants to merge 6 commits intodevelopfrom
mypy-check-untyped-defs

Conversation

@tgamblin
Copy link
Copy Markdown
Member

@tgamblin tgamblin commented Feb 23, 2023

mypy can do much more aggressive (and useful) type checking for us, but we can't use it because the Spack codebase doesn't yet pass the aggressive checking.

The Spack codebase is getting pretty large and in some cases unwieldy, so static checking like this should help us. In particular, with --check-untyped-defs, we could catch nasty and time-consuming issues like #35632, which cost several days of multiple peoples' time.

Another big win for mypy checks is that they can see through * imports like those that we use in package.py files. So we could find undefined/unused variables in core package.py's, which we currently miss.

At first glance, this is going to require over 1,000 fixes throughout the codebase, so we'll need to do it somewhat gradually. I started this branch to collect the needed changes as commits. We can keep it rebased on develop, and we can pull commits off of here into other PRs to commit partial changes as they're ready.

When this (finally) goes green, we can merge the check_untyped_defs = true line in pyproject.toml and start checking PRs more aggressively.

If we get this in, we could consider even more aggressive checksum, like:

  • --disallow-untyped-calls
  • --disallow-untyped-defs
  • --disallow-incomplete-defs

Those essentially mandate type annotations everywhere, so we may not want to go that far just yet.

  • enable check_untyped_defs in pyproject.toml
  • start making changes to make mypy happy

@spackbot-app spackbot-app bot added commands compilers core PR affects Spack core functionality fetching locking sbang tests General test capability(ies) utilities labels Feb 23, 2023
@tgamblin tgamblin force-pushed the mypy-check-untyped-defs branch from 8798551 to 3d42421 Compare February 23, 2023 10:18
@tgamblin tgamblin mentioned this pull request Feb 23, 2023
1 task
tgamblin added a commit that referenced this pull request Feb 23, 2023
`colify` is an old module in Spack that still uses `**kwargs` liberally. We should be
more explicit. Doing this eliminates the need for many checks (can't pass the wrong arg
if it isn't allowed) and makes the function documentation more clear.

I'm pulling this out of #35639 as I think it helps the code regardless.

- [x] use named arguments instead of `kwargs`
tgamblin added a commit that referenced this pull request Feb 23, 2023
`colify` is an old module in Spack that still uses `**kwargs` liberally. We should be
more explicit. Doing this eliminates the need for many checks (can't pass the wrong arg
if it isn't allowed) and makes the function documentation more clear.

I'm pulling this out of #35639 as I think it helps the code regardless.

- [x] use named arguments instead of `kwargs`
@tgamblin tgamblin force-pushed the mypy-check-untyped-defs branch from 3d42421 to b1e6a24 Compare February 23, 2023 10:47
@tgamblin tgamblin requested a review from trws February 23, 2023 10:50
`mypy` only understands `sys.platform == "win32"`, not indirect assignments of that
value to things like `is_windows`. If we don't use the accepted platform checks, `mypy`
registers many Windows-only symbols as not present on Linux, when it should skip the
checks for platform-specific code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

commands compilers core PR affects Spack core functionality fetching locking sbang tests General test capability(ies) utilities

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant