Skip to content
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

Overrides in pyproject.toml not excluding specified modules #16316

Open
davibicudo opened this issue Oct 23, 2023 · 1 comment
Open

Overrides in pyproject.toml not excluding specified modules #16316

davibicudo opened this issue Oct 23, 2023 · 1 comment
Labels
bug mypy got something wrong topic-configuration Configuration files and flags

Comments

@davibicudo
Copy link

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

@davibicudo davibicudo added the bug mypy got something wrong label Oct 23, 2023
@AlexWaygood AlexWaygood added the topic-configuration Configuration files and flags label Oct 23, 2023
@gsakkis
Copy link

gsakkis commented Nov 5, 2023

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:

  • Add a test_module/__init__.py file
  • Run mypy with --explicit-package-bases
  • Set explicit_package_bases=true in the [tool.mypy] section of pyproject.toml.

More details here.

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

No branches or pull requests

3 participants