Skip to content

Comments

Add MYPYSTICT lintrunner job#1077

Draft
jacobhinkle wants to merge 19 commits intomainfrom
mypy_config
Draft

Add MYPYSTICT lintrunner job#1077
jacobhinkle wants to merge 19 commits intomainfrom
mypy_config

Conversation

@jacobhinkle
Copy link
Collaborator

@jacobhinkle jacobhinkle commented Oct 12, 2023

Enabling mypy will require some fixes to our python code but should help keep our ever-growing python codebase clean. Similar to the clang-tidy situation, this may mean we should either fix a bunch of errors up front or CI will fail when modifying these files in the future.

The mypy lintrunner jobs were not running since these files were
missing. Enabling this will require some fixes to our python code but
should help keep our ever-growing python codebase clean.

[mypy]
python_version = 3.8
#plugins = mypy_plugins/check_mypy_version.py, numpy.typing.mypy_plugin
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is the only change I made to these files. I don't think we need the mypy version check since we install 1.4.0 in the lintrunner config anyway. I haven't looked through everything else yet. We might want a minimal set of options, or to disable the strict version.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Another simple approach is to remove the strict version and also remove the --config=mypy.ini argument (and these files), so that we'd use the default settings. We'd probably at least want to set --ignore-missing-imports, so perhaps trimming down mypy.ini to just a few options is preferable.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if we should just blankly skip checks on specific libraries? i.e.

[mypy]
ignore_missing_imports = True

I know little about mypy, let me know if I'm talking non-sense 😆

mypy-strict.ini Outdated
# files.

[mypy]
python_version = 3.8
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

See #1078

@@ -0,0 +1 @@
.lintrunner.toml No newline at end of file
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure why this symlink is needed, but I have needed it to run lintrunner on my workstation also.

Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm. this shouldn't be needed. It's probably some funny script issue for lintrunner.

Meanwhile, can we change the command to lintrunner --config .lintrunner.toml XXXXXXX

self._cls_name = cls_name

def get_cls(self):
def get_cls(self) -> Any:
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I fixed this one missing return type annotation to try and trigger a mypy run over this file. Locally when I run lintrunner nvfuser/nvfuser_version.py I get a number of other errors.

@jjsjann123
Copy link
Collaborator

Ha, this is likely something that gets accidentally dropped when switching to lintrunner.
Thanks for patching this.

Copy link
Collaborator

@jjsjann123 jjsjann123 left a comment

Choose a reason for hiding this comment

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

some nitpick here and there.

@@ -0,0 +1 @@
.lintrunner.toml No newline at end of file
Copy link
Collaborator

Choose a reason for hiding this comment

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

hmm. this shouldn't be needed. It's probably some funny script issue for lintrunner.

Meanwhile, can we change the command to lintrunner --config .lintrunner.toml XXXXXXX


[mypy]
python_version = 3.8
#plugins = mypy_plugins/check_mypy_version.py, numpy.typing.mypy_plugin
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if we should just blankly skip checks on specific libraries? i.e.

[mypy]
ignore_missing_imports = True

I know little about mypy, let me know if I'm talking non-sense 😆

@jacobhinkle jacobhinkle changed the title Add mypy.ini and mypy-strict.ini Add MYPYSTICT lintrunner job Jul 24, 2025
@github-actions
Copy link

github-actions bot commented Jul 24, 2025

Review updated until commit d3cb42b

Description

  • Add MYPYSTRICT lintrunner job for strict type checking

  • Update nvfuser_version.py to include type hint

  • Modify .github/workflows/lint.yml to use .lintrunner.toml

  • Remove MYPY and only run MYPYSTRICT

  • Update Python version to 3.12 and exclude some files


Changes walkthrough 📝

Relevant files
Enhancement
nvfuser_version.py
Add type hint to `get_cls`                                                             

python/nvfuser/nvfuser_version.py

  • Add return type hint to get_cls method
+1/-1     
lint.yml
Update lintrunner configuration                                                   

.github/workflows/lint.yml

  • Update lintrunner command to use .lintrunner.toml
  • Skip CLANGTIDY in lintrunner
  • +2/-2     
    .lintrunner.toml
    Update MYPYSTRICT configuration                                                   

    .lintrunner.toml

  • Remove MYPY linter configuration
  • Update MYPYSTRICT linter configuration
  • +0/-21   
    mypy-strict.ini
    Add mypy-strict.ini                                                                           

    mypy-strict.ini

    • Add strict mypy configuration for PyTorch codebase
    +67/-0   

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    🧪 No relevant tests
    ⚡ Recommended focus areas for review

    Type Hinting

    The new method get_cls should have a return type specified. Currently, it uses Any, which defeats the purpose of using mypy for type checking.

    def get_cls(self) -> Any:
    MYPYSTRICT Configuration

    The lintrunner command in the CI pipeline now includes MYPYSTRICT but the configuration file mypy-strict.ini is not being used. Ensure that the lintrunner command points to the correct configuration file.

    lintrunner --config .lintrunner.toml --force-color --skip CLANGTIDY --all-files
    MYPY Removal

    The MYPY linter configuration has been removed and replaced with MYPYSTRICT. Verify that all necessary configurations have been transferred to MYPYSTRICT to maintain the same level of type checking.

    [[linter]]

    I don't know if this is required but we currently get a warning about
    missing .lintrunner.private.toml even though that should be a link to
    .lintruner.toml
    @jacobhinkle
    Copy link
    Collaborator Author

    @jjsjann123 I updated this PR and I think it's ready for another look. If it gets to be a pain fixing typing errors we could disable it. What do you think?

    @jacobhinkle
    Copy link
    Collaborator Author

    Running locally via lintrunner I get mypy errors, but for some reason none are found in github CI. I need to figure that out before this will be considered ready.

    @jjsjann123
    Copy link
    Collaborator

    @jjsjann123 I updated this PR and I think it's ready for another look. If it gets to be a pain fixing typing errors we could disable it. What do you think?

    sounds good to me.
    Sorry this somehow dropped off my radar. 🙇

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Labels

    None yet

    Projects

    None yet

    Development

    Successfully merging this pull request may close these issues.

    2 participants