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 does not work when file contains invalid syntax? #14670

Open
pawamoy opened this issue Feb 10, 2023 · 0 comments
Open

exclude does not work when file contains invalid syntax? #14670

pawamoy opened this issue Feb 10, 2023 · 0 comments
Labels
bug mypy got something wrong topic-configuration Configuration files and flags

Comments

@pawamoy
Copy link

pawamoy commented Feb 10, 2023

Bug Report

I'm having an issue with exclude. Basically, I exclude my tests/fixtures folder because it contains code with syntax that is only supported by Python 3.8, 3.9, etc, while my project supports Python 3.7. So the files in tests/fixtures contain invalid syntax on Python 3.7.

When I run mypy on Python 3.7, it errors with this:

tests/fixtures/validation_38.py:1: error: invalid syntax [syntax]
Found 1 error in 1 file (errors prevented further checking)

I exclude the folder with exclude = tests/fixtures in mypy.ini.
I tried excluding the file name directly, for example with exclude = validation_38\.py but it still fails the same way.

To Reproduce

# tests/fixtures/validation_38.py
def full(ctx, a: int, /, b: int, *c: int, d: int, e: int = 0, **f: int):
    pass

Checking only the parent folder, I'm able to exclude it:

% python3.7 -m mypy --exclude validation_38.py --ignore-missing-imports tests/fixtures/
Success: no issues found in 8 source files

Any other way fails:

% python3.7 -m mypy --exclude validation_38.py --ignore-missing-imports tests          
tests/fixtures/validation_38.py:1: error: invalid syntax  [syntax]
Found 1 error in 1 file (errors prevented further checking)
% python3.7 -m mypy --exclude fixtures/validation_38.py --ignore-missing-imports tests
tests/fixtures/validation_38.py:1: error: invalid syntax  [syntax]
Found 1 error in 1 file (errors prevented further checking)
% python3.7 -m mypy --exclude '.*/validation_38\.py' --ignore-missing-imports tests
tests/fixtures/validation_38.py:1: error: invalid syntax  [syntax]
Found 1 error in 1 file (errors prevented further checking)
% python3.7 -m mypy --exclude tests/fixtures --ignore-missing-imports tests
tests/fixtures/validation_38.py:4: error: invalid syntax  [syntax]
Found 1 error in 1 file (errors prevented further checking)
% python3.7 -m mypy --exclude fixtures --ignore-missing-imports tests 
tests/fixtures/validation_38.py:4: error: invalid syntax  [syntax]
Found 1 error in 1 file (errors prevented further checking)

Expected Behavior

Invalid syntax errors should be ignored if the file in question is excluded.
It seemed to work previously (before 1.0.0?).

Actual Behavior

An excluded file with invalid syntax makes mypy terminate with an error.

Your Environment

  • Python version used: 3.7
  • Mypy version used: 1.0.0
  • Mypy command-line flags: see above
  • Mypy configuration options from mypy.ini (not used in the examples above):
[mypy]
ignore_missing_imports = true
exclude = tests/fixtures
warn_unused_ignores = true
show_error_codes = true

Possibly related to #9981 and #6897.

@pawamoy pawamoy added the bug mypy got something wrong label Feb 10, 2023
pawamoy added a commit to pawamoy/duty that referenced this issue Feb 10, 2023
@AlexWaygood AlexWaygood added the topic-configuration Configuration files and flags label Feb 10, 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

2 participants