Michael Reed
Michael Reed

Reputation: 21

Mypy not displaying errors when target file has absolute path

mypy seems to be ignoring at least some errors when called on a file using an absolute address. I had originally presumed this was an issue with my project but it's very easy for me to reproduce on a basic setup. If you have reason to believe this an issue with my machine setup, I would love to know - I'm currently unable to use mypy linting in vscode due to this issue.

$ .venv/bin/mypy --strict /home/mike/Documents/deleteMe/pipenv_testing/sample.py 
Success: no issues found in 1 source file

$ .venv/bin/mypy --strict ./sample.py 
sample.py:4: error: Function is missing a type annotation  [no-untyped-def]
Found 1 error in 1 file (checked 1 source file)

To Reproduce

  1. Generate a file containing one or more simple mypy errors, example below (error only occurs with strict set on):
def do_a_thing(invar):
    return invar + 1
  1. Install mypy (I'm using pipenv to generate a virtualenv using pipenv install mypy)
  2. Run mypy against a relative path to the simple python file generated above in a configuration that expects an error and verify the error is displayed correctly. For example: .venv/bin/mypy --strict ./sample.py
  3. Repeat step 3 but use an absolute path to the target python file and observe that no issues are reported. For example: .venv/bin/mypy --strict /home/mike/Documents/deleteMe/pipenv_testing/sample.py

Expected Behavior It's expected that both conditions should yield identical error results rather than the absolute path call yielding no issues/errors.

My Environment

Upvotes: 0

Views: 718

Answers (1)

Michael Reed
Michael Reed

Reputation: 21

Leaving this up in case it helps anyone else but this is an issue with ~0.990 versions of mypy that is now resolved in the master branch with a patch coming out shortly.

Github issue: https://github.com/python/mypy/issues/14080

Upvotes: 1

Related Questions