leinardi / mypy-pycharm

A plugin providing both real-time and on-demand scanning of Python files with Mypy from within PyCharm/IDEA.
Apache License 2.0
194 stars 31 forks source link

Plugin fails to report errors which are reported by running mypy on command line #21

Closed uglycoyote closed 5 years ago

uglycoyote commented 6 years ago

Step 1: Are you in the right place?

Step 2: Describe your environment

Step 3: Describe the problem:

I'm encountering cases where the plugin is failing to list mypy errors in the error list window, but running mypy on the command line shows the errors.

I'm getting this in a large and complex proprietary project that I cannot paste the source of, but I have reproduced similar behaviour in a small test project

Steps to reproduce:

  1. Make a new project File->New Project
  2. Make two new python files in the project, File1.py and File2.py
  3. Add the following contents to the files

in File1.py:

class MyClass:

    x:int
    y:str

in File2.py:

import File1

from typing import List

def SomeFunction( stuffs : List[File1.MyClass] ) -> None:

    a = File1.MyClass()
    a.foo = "bar"

    b = 1
    b = "2"

    for stuff in stuffs:
        stuff.foo = "bar"
        stuff["hello"] = "goodbye"

Observed Results:

On the command line, I get the following errors from the same mypy executable that the plugin installed for me automatically:

PS C:\Users\admin\PycharmProjects\Test> C:\Users\admin\PycharmProjects\Test\venv\Scripts\mypy.exe .\File2.py
File2.py:9: error: "MyClass" has no attribute "foo"
File2.py:12: error: Incompatible types in assignment (expression has type "str", variable has type "int")
File2.py:15: error: "MyClass" has no attribute "foo"
File2.py:16: error: Unsupported target for indexed assignment

but in the mypy plugin window I only get one of the errors, only the one about the variable b

image

None of the errors related to the MyClass defined in File1.py appear.

When I run using the "Check Module" button in the plugin I do successfully get all four errors in this case

image

However, I'm unsatisfied with this for two reasons:

leinardi commented 6 years ago

The main (and hopefully) only difference should be that the plugin is using skip for the follow-import parameter:

/home/rleinardi/Workspace/misc/my/gsi/venv/bin/mypy --show-column-numbers --follow-imports skip /home/rleinardi/Workspace/misc/my/gsi/gsi/presenter.py

The reason why I am using it is that without it, if I scan a specific file, I get errors also from all the imported files.

uglycoyote commented 6 years ago

@leinardi Yes the --follow-imports skip does explain why the "Check Current File" option gave less errors than I expected. Like you, I also was only interested in seeing only errors from the current file, but was hoping it would be a complete list of errors. Not following the imports has the unfortunate effect of suppressing errors in the current file related to types defined in those external files.

So, maybe having the follow-imports thing be optional would be good.

I'm still a bit puzzled why, in my larger project, there were errors that didn't appear in the "Check Module" list which did appear on the command line. But that may be due to my poor understanding of what a "module" is. (#20 will help with this). On the command line I was running mypy on a particular directory which was working well for me, but there doesn't seem to be the option for that in the plugin, unless module is a synonym for directory. I'm not really wanting to use "Check Project" because my project is very large. I tried it right now just too see what would happen but it just made PyCharm completely unresponsive for the last five minutes or so.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because it has not had activity in the last 60 days.

aviskase commented 5 years ago

What about switching from --follow-imports skip to --follow-imports silent ? For our project it seems to be fixing opposite issue of reporting false positives (which are not reported during per module run)