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

mypy 0.990 shows no errors when passing source directory as absolute path #14042

Closed
intgr opened this issue Nov 8, 2022 · 20 comments · Fixed by #14060
Closed

mypy 0.990 shows no errors when passing source directory as absolute path #14042

intgr opened this issue Nov 8, 2022 · 20 comments · Fixed by #14060
Labels
bug mypy got something wrong

Comments

@intgr
Copy link
Contributor

intgr commented Nov 8, 2022

Bug Report

I noticed that after upgrading to 0.990, mypy in djangorestframework-stubs CI no longer finds any errors.

It seems this happens when the source folder is passed as a full path, instead of relative path. $PWD is the full path of the current working directory:

% mypy --config-file $PWD/mypy.ini --show-traceback --hide-error-context ./drf_source/tests |tail -n1
Found 569 errors in 48 files (checked 83 source files)
% mypy --config-file $PWD/mypy.ini --show-traceback --hide-error-context $PWD/drf_source/tests |tail -n1
Success: no issues found in 83 source files

Maybe, just maybe, this is related to #13768? EDIT: seems not to be, various --follow-imports= options have no effect.

To Reproduce

  1. Check out https://github.com/intgr/djangorestframework-stubs branch update-to-mypy-0.990
  2. Install dependencies from requirements.txt in a virtualenv
  3. Upgrade to mypy 0.990
  4. Run python scripts/typecheck_tests.py, which populates the drf_source directory
  5. Try running the commands above

Your Environment

@intgr
Copy link
Contributor Author

intgr commented Nov 8, 2022

I can also reproduce this when I comment out mypy plugins in mypy.ini

@intgr
Copy link
Contributor Author

intgr commented Nov 8, 2022

Also reproduced this in another project of mine.

@hauntsaninja
Copy link
Collaborator

Does it reproduce with --no-namespace-packages?

@intgr
Copy link
Contributor Author

intgr commented Nov 8, 2022

Yes. Adding --no-namespace-packages does not solve the issue, still getting "no issues found".

@ilevkivskyi
Copy link
Member

ilevkivskyi commented Nov 8, 2022

Also do you have $PWD in your PYTHONPATH maybe? What was the last mypy version that didn't have this issue? Around 0.970 mypy started interpreting everything in PYTHONPATH as third party packages and silencing them. You can try --no-silence-site-packages

@intgr
Copy link
Contributor Author

intgr commented Nov 8, 2022

This issue does not occur with 0.982

% mypy --version
mypy 0.982 (compiled: yes)
% mypy --config-file $PWD/mypy.ini --show-traceback --hide-error-context --no-namespace-packages $PWD/drf_source/tests |tail -n1
.../djangorestframework-stubs/mypy.ini: [mypy]: disable_error_code: Invalid error code(s): empty-body
Found 575 errors in 49 files (checked 83 source files)

PYTHONPATH is unset in the shell I'm testing this from. The typecheck_tests.py script does indeed add $PWD to PYTHONPATH, but it doesn't seem to affect this issue.

@ilevkivskyi
Copy link
Member

Hm, probably the easiest way is to bisect mypy commits. Since the problem looks really bizzare.

@intgr
Copy link
Contributor Author

intgr commented Nov 8, 2022

Adding --no-silence-site-packages with mypy 0.990 and using $PWD only mostly prints errors from site-packages modules, not the project itself.

Are you unable to reproduce this in any of your own projects?

I can give bisecting a try.

@ilevkivskyi
Copy link
Member

Are you unable to reproduce this in any of your own projects?

No, but I also don't have many.

I can give bisecting a try.

That would be great, since I will not have much time today/tomorrow.

@intgr
Copy link
Contributor Author

intgr commented Nov 8, 2022

Git bisected it to:

00ca6bf is the first bad commit

Which is #13768 as I initially suspected.

@ilevkivskyi
Copy link
Member

@JukkaL could you please take a look?

@intgr
Copy link
Contributor Author

intgr commented Nov 8, 2022

I was wrong before. --no-silence-site-packages does have an effect on the output but it's really weird.

  • mypy --no-silence-site-packages $PWD/drf_source/tests 142 errors in 18 files (checked 83 source files) -- most of these are site-pacakges errors, but 6 are from project itself!
  • mypy --no-silence-site-packages ./drf_source/tests 142 errors in 18 files (checked 83 source files), same as above
  • mypy $PWD/drf_source/tests no issues found in 83 source files
  • mypy ./drf_source/tests 569 errors in 48 files (checked 83 source files) -- expected behavior

@intgr
Copy link
Contributor Author

intgr commented Nov 8, 2022

The behavior of --no-silence-site-packages is also reproducible in mypy 0.982. But the $PWD vs . behavior does not reproduce there.

@trivialfis
Copy link

Just to confirm I'm experiencing the same issue with the latest mypy. But the issue is not reproducible in every environment it seems. I run into the same issue as described by @intgr on my local machine, but our CI script can report errors correctly using the same version of mypy.

@JukkaL
Copy link
Collaborator

JukkaL commented Nov 9, 2022

I will investigate. This might be caused by absolute paths treated differently from relative paths, but we'll see.

@JacobHayes
Copy link

In case it is useful, -p is also incorrectly omitting errors, matching the absolute path behavior (perhaps -p resolves to an absolute path?). I can confirm relative paths work correctly.

@najtin
Copy link

najtin commented Nov 9, 2022

I think this is the cause to microsoft/vscode-python#20182

EDIT: see my next comment, this issue here does not seem to cause the linting problem.

The issue is about mypy not find any error when run by the linter but finding errors when the exact same command is running in a terminal. Notice the relative paths.
Linter inside vscode:

> ./.venv/bin/python ~/.vscode-oss/extensions/ms-python.python-2022.16.1-universal/pythonFiles/linter.py -m mypy --follow-imports=silent --ignore-missing-imports --show-column-numbers --no-pretty ./rootsnakes/app.py
cwd: .
##########Linting Output - mypy##########

Success: no issues found in 1 source file

same code in terminal:

./.venv/bin/python ~/.vscode-oss/extensions/ms-python.python-2022.16.1-universal/pythonFiles/linter.py -m mypy --follow-imports=silent --ignore-missing-imports --show-column-numbers --no-pretty ./lol.py
lol.py:1:1: error: Missing return statement  [return]
Found 1 error in 1 file (checked 1 source file)

See the linked issue for a more detailed description.

@najtin
Copy link

najtin commented Nov 10, 2022

also maybe some of the issues reported here are definitely related to #14054

EDIT: through some experimentation i found that the vs-code linting issue is definitely caused by #14054 and not by this issue here. Some package managers automatically add the current working directory to the path, e.g. running poetry install. It seems very likely that this could also break numerous CI setups. @trivialfis @intgr Here i cover in detail how to get reproduce the issue microsoft/vscode-python#20182 (comment) in case anyone get here with the same issue as me.
It seems that both issues are caused by the same changes in #13768

JukkaL added a commit that referenced this issue Nov 10, 2022
that were under a directory in `sys.path`, which sometimes includes
the current working directory, resulting in no errors reported at
all.

Fixes #14042.
JukkaL added a commit that referenced this issue Nov 10, 2022
#13768 had a bug so that errors were sometimes silenced in files that
were under a directory in `sys.path`. `sys.path` sometimes includes the 
current working directory, resulting in no errors reported at all. Fix it by 
always reporting errors if a file was passed on the command line (unless
*explicitly* silenced).

When using import following errors can still be ignored, which is 
questionable, but this didn't change recently so I'm not addressing it 
here.

Fixes #14042.
@JukkaL
Copy link
Collaborator

JukkaL commented Nov 10, 2022

The issue should be fixed on master. It would be great if somebody can validate that it works. We'll have a 0.99x poinrt release (probably next week) that will include the fix.

@intgr
Copy link
Contributor Author

intgr commented Nov 10, 2022

Thanks! I can confirm that this fixes my original use case.

svalentin pushed a commit that referenced this issue Nov 10, 2022
#13768 had a bug so that errors were sometimes silenced in files that
were under a directory in `sys.path`. `sys.path` sometimes includes the 
current working directory, resulting in no errors reported at all. Fix it by 
always reporting errors if a file was passed on the command line (unless
*explicitly* silenced).

When using import following errors can still be ignored, which is 
questionable, but this didn't change recently so I'm not addressing it 
here.

Fixes #14042.
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Nov 14, 2022
0.10.1
* Work around python/mypy#14042.
* Add support for Python 3.11.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants