Skip to content

Exclude not working properly for version 0.931 #11936

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

Closed
RemyLau opened this issue Jan 7, 2022 · 6 comments
Closed

Exclude not working properly for version 0.931 #11936

RemyLau opened this issue Jan 7, 2022 · 6 comments
Labels
bug mypy got something wrong

Comments

@RemyLau
Copy link

RemyLau commented Jan 7, 2022

In my current setup, I use tox (version 3.24.5) to run mypy for type checking my codebase. I specified a few files to be excluded from the checks in the setup.cfg file. Previously (mypy version 0.930) it works fine, but after updating mypy to version 0.931, it does not seem to properly exclude the files when called via tox.

The error

Below is the error message by running tox -e mypy, where it raises error due to files that I've excluded: src/NLEval/valsplit/, src/NLEval/model/ and /src/NLEval/graph/.

mypy recreate: /mnt/ufs18/home-026/liurenmi/repo/NetworkLearningEval/.tox/mypy
mypy installdeps: mypy==0.931
mypy installed: mypy==0.931,mypy-extensions==0.4.3,tomli==2.0.0,typing_extensions==4.0.1
mypy run-test-pre: PYTHONHASHSEED='3030470107'
mypy run-test: commands[0] | mypy src/NLEval
src/NLEval/valsplit/Holdout.py:37: error: Name "train_ratio" already defined on line 29
src/NLEval/valsplit/Holdout.py:37: error: "Callable[[TrainValTest], Any]" has no attribute "setter"
src/NLEval/valsplit/Holdout.py:46: error: Name "test_ratio" already defined on line 33
src/NLEval/valsplit/Holdout.py:46: error: "Callable[[TrainValTest], Any]" has no attribute "setter"
src/NLEval/model_trainer/base.py:78: error: "BaseGraph" has no attribute "mat"
src/NLEval/model/label_propagation.py:76: error: "BaseGraph" has no attribute "propagate"
src/NLEval/model/label_propagation.py:80: error: "BaseGraph" has no attribute "propagate"
src/NLEval/graph/sparse.py:32: error: Name "weighted" already defined on line 22
src/NLEval/graph/sparse.py:32: error: "Callable[[SparseGraph], Any]" has no attribute "setter"
src/NLEval/graph/sparse.py:37: error: Name "directed" already defined on line 27
src/NLEval/graph/sparse.py:37: error: "Callable[[SparseGraph], Any]" has no attribute "setter"
src/NLEval/graph/dense.py:174: error: overloaded function has no attribute "setter"
Found 12 errors in 5 files (checked 39 source files)
ERROR: InvocationError for command /mnt/ufs18/home-026/liurenmi/repo/NetworkLearningEval/.tox/mypy/bin/mypy src/NLEval (exited with code 1)
______________________________________________________________________________________ summary _______________________________________________________________________________________
ERROR:   mypy: commands failed

Previous version (0.930) works fine

If I set the mypy version to 0.930 (the previous version), it runs fine:

mypy recreate: /mnt/ufs18/home-026/liurenmi/repo/NetworkLearningEval/.tox/mypy
mypy installdeps: mypy==0.930
mypy installed: mypy==0.930,mypy-extensions==0.4.3,tomli==2.0.0,typing_extensions==4.0.1
mypy run-test-pre: PYTHONHASHSEED='2815542976'
mypy run-test: commands[0] | mypy src/NLEval
Success: no issues found in 30 source files
______________________________________________________________________________________ summary _______________________________________________________________________________________
  mypy: commands succeeded
  congratulations :)

Command-line interface works fine

However, if I run using the command line interface, it properly excludes the files.

Configuration

Here's the relevant lines in my setup.cfg for setting up mypy configuration:

[mypy]                                                                          
ignore_missing_imports = true                                                   
follow_imports = skip                                                           
exclude =                                                                       
    src/NLEval/graph/                                                           
    src/NLEval/valsplit/                                                        
    src/NLEval/metrics.py  
@RemyLau RemyLau added the bug mypy got something wrong label Jan 7, 2022
@hauntsaninja
Copy link
Collaborator

Unfortunately, the changes 0.930 made to exclude (supporting newline delimited exclude in mypy.ini) was a regression for many users, so 0.931 rolled back some of the change.

Here's what you can do to make things work:

mypy.ini

[mypy]
exclude = (?x)(
    src/NLEval/graph/                                                           
    |src/NLEval/valsplit/                                                        
    |src/NLEval/metrics.py  
  )

pyproject.toml

[tool.mypy]
exclude = [
    "src/NLEval/graph/",
    "src/NLEval/valsplit/",
    "src/NLEval/metrics.py",
]

pyproject.toml (if you love regexes)

[tool.mypy]
exclude = '''(?x)(
    src/NLEval/graph/                                                           
    |src/NLEval/valsplit/                                                        
    |src/NLEval/metrics.py  
)'''

See https://mypy.readthedocs.io/en/latest/config_file.html#confval-exclude for details

@RemyLau
Copy link
Author

RemyLau commented Jan 8, 2022

Great! This works! Thanks a lot!

RemyLau added a commit to krishnanlab/obnb that referenced this issue Jan 8, 2022
RemyLau added a commit to krishnanlab/obnb that referenced this issue Jan 8, 2022
* Catch None if checkType, and use checkNullableType to accept None, closes #76

* Remove explicit type check for ascending

* Implement BaseRandomSplit and RandomRatioPartition

* Implement RandomRatioHoldout, closes #67

Did not implement cross validation, could be simply passed the sklearn skf.split

* Move mypy config into setup.cfg

* Fix mypy version

* Update mypy config, see python/mypy#11936
@major-mayer
Copy link

Hi @hauntsaninja
I tried to use the syntax for the Mypy.ini file that you proposed:

# Global options:

[mypy]
namespace_packages = True
; explicit_package_bases = True
follow_imports = normal
show_column_numbers = True
warn_unused_configs = True
plugins = pydantic.mypy 
exclude = (?x)(
    src/helpers/protobuf_generated/
)

However, mypy is still returning some errors for files inside src/helpers/protobuf_generated/.
Any idea why this could be the case?

Document saved: /home/laurenz/ModuleWorks/checkouts/ngsp-web-api/mypy.ini
[47] Using config file: mypy.ini
[47] Received python path from Python extension: /home/laurenz/.virtualenvs/ngsp-web-api-GBFOw5Ei/bin/python
[47] Running dmypy in folder /home/laurenz/ModuleWorks/checkouts/ngsp-web-api
/home/laurenz/.virtualenvs/ngsp-web-api-GBFOw5Ei/bin/python -m mypy.dmypy --status-file '/home/laurenz/.config/Code - OSS/User/workspaceStorage/da188d075a6bf7ea13442f9de2591274/matangover.mypy/dmypy-3951f859caa84b9756c1fc5b8a79f1be049959b4-11271.json' run --log-file '/home/laurenz/.config/Code - OSS/User/workspaceStorage/da188d075a6bf7ea13442f9de2591274/matangover.mypy/dmypy-3951f859caa84b9756c1fc5b8a79f1be049959b4.log' -- . --show-column-numbers --no-error-summary --no-pretty --no-color-output --config-file mypy.ini --python-executable /home/laurenz/.virtualenvs/ngsp-web-api-GBFOw5Ei/bin/python
[47] Mypy output:
[... many other errors...]
src/helpers/protobuf_generated/toolpath_pb2.py:28:23: error: Unexpected keyword argument "filename" for "Descriptor"  [call-arg]
/home/laurenz/.virtualenvs/ngsp-web-api-GBFOw5Ei/lib/python3.9/site-packages/google-stubs/protobuf/descriptor.pyi:33:5: note: "Descriptor" defined here

@hauntsaninja
Copy link
Collaborator

Likely this, from the docs: https://mypy.readthedocs.io/en/stable/command_line.html#cmdoption-mypy-exclude

In particular, --exclude does not affect mypy’s import following. You can use a per-module follow_imports config option to additionally avoid mypy from following imports and checking code you do not wish to be checked.

@major-mayer
Copy link

Ah yes thanks, I added the follwing to the config and it now doesn't report the errors anymore.

[mypy-src.helpers.protobuf_generated.*]
follow_imports = skip

@Avasam
Copy link
Contributor

Avasam commented May 24, 2024

(cross-linking to #10377 to help issue and discussion discoverability)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

4 participants