python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.2k stars 2.78k forks source link

Overrides in pyproject.toml not excluding specified modules #16316

Open davibicudo opened 10 months ago

davibicudo commented 10 months ago

When running mypy with a pyproject.toml configuration that uses the [[tool.mypy.overrides]] section to exclude specific modules, the specified modules are still being type-checked, contrary to expectations.

Steps to Reproduce:

Set up a pyproject.toml with mypy configurations using the [[tool.mypy.overrides]] section to exclude a specific module:

[tool.mypy]
python_version = "3.8"

[[tool.mypy.overrides]]
module = ["test_module.sample"]
ignore_errors = true

Have a sample module with evident type errors:

# test_module/sample.py
def faulty_function() -> int:
    return "This should be an integer!"

Run mypy with the provided configuration:

mypy test_module/ --config-file pyproject.toml

Expected Behavior: The module test_module.sample should be excluded from type-checking and no errors should be reported.

Actual Behavior: mypy reports type errors from the module test_module.sample, indicating that it is not being excluded as specified in the configuration.

Mypy Version: 1.6.1

gsakkis commented 10 months ago

What happens is that the path test_module/sample.py is mapped to the module sample instead of test_module.sample:

mypy test_module --verbose 2>&1 | grep source
LOG:  Found source:           BuildSource(path='test_module/sample.py', module='sample', ...)
Found 1 error in 1 file (checked 1 source file)

To fix it you can do any of the following:

More details here.