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

"exclude" param doesn't work in toml settings #15940

Closed
mshinkareva opened this issue Aug 23, 2023 · 2 comments
Closed

"exclude" param doesn't work in toml settings #15940

mshinkareva opened this issue Aug 23, 2023 · 2 comments
Labels
bug mypy got something wrong topic-configuration Configuration files and flags

Comments

@mshinkareva
Copy link

mshinkareva commented Aug 23, 2023

Bug Report

"exclude" param doesn't work in toml settings

To Reproduce

  1. I have .pre-commit-config.yaml
repos:
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v4.2.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
        exclude: .yaml
      - id: check-added-large-files
        exclude: ^(reports/|references/)
  - repo: https://github.com/asottile/seed-isort-config
    rev: v1.9.4
    hooks:
      - id: seed-isort-config
  - repo: https://github.com/pre-commit/mirrors-isort
    rev: v4.3.21  # pick the isort version you'd like to use from https://github.com/pre-commit/mirrors-isort/releases
    hooks:
      - id: isort
        entry: black --skip-string-normalization
        exclude: ^(alembic)
  - repo: https://github.com/psf/black
    rev: 22.3.0
    hooks:
      - id: black
        entry: black --skip-string-normalization
  - repo: local
    hooks:
      - id: flake8
        name: flake8
        entry: flake8
        language: system
  - repo: local
    hooks:
      - id: mypy
        name: mypy
        entry: mypy
        language: system
        types: [python]
        require_serial: true
        exclude: ^(test|references/|reports/|alembic/)
  1. I wanted to describe some params from .pre-commit-config.yaml to pyproject.toml

in .pre-commit-config.yaml

  - repo: local
    hooks:
      - id: mypy
        name: mypy
        entry: mypy
        language: system
        types: [python]
        require_serial: true

in pyproject.toml

[tool.mypy]
exclude = ['.*env\.py']
plugins = "pydantic.mypy"
ignore_missing_imports = true
  1. Start
pre-commit run --all-files

Expected Behavior

All files as env.py has been ignored by mypy

Actual Behavior

alembic/env.py:19: error: Argument 1 to "fileConfig" has incompatible type "Optional[str]"; expected "Union[Union[str, bytes, PathLike[str], PathLike[bytes]], IO[str], RawConfigParser]"  [arg-type]
Found 1 error in 1 file (checked 146 source files)

Your Environment

  • Mypy version 1.5.1:
  • Python version used: 3.9
@mshinkareva mshinkareva added the bug mypy got something wrong label Aug 23, 2023
@sobolevn
Copy link
Member

@mshinkareva I am sorry, but is it really a mypy issue? This looks like pre-commit issue. Can you please reproduce this without pre-commit?

Let me explain (I am not very familiar with pre-commit):

  1. exclude means that changes in these files do not trigger pre-commit run
  2. Some other files do trigger this job
  3. All project files are passed to mypy to be checked (???)
  4. mypy analyzes all files and all dependecies as it should do

I think that the workaround for this would be adding exclude to mypy config: https://mypy.readthedocs.io/en/stable/config_file.html#confval-exclude or you can just silence warnings for this specific file, see https://mypy.readthedocs.io/en/stable/config_file.html#using-a-pyproject-toml-file (or fix the issue there).

Do you agree? :)

@AlexWaygood AlexWaygood added the topic-configuration Configuration files and flags label Aug 23, 2023
@hauntsaninja
Copy link
Collaborator

See also #13916 . Use pass_filenames: false

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Aug 24, 2023
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

4 participants