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

Errors not always reported for a file in incremental mode (reopening #4043) #12354

Open
mrolle45 opened this issue Mar 15, 2022 · 1 comment
Open
Labels
bug mypy got something wrong topic-incremental

Comments

@mrolle45
Copy link

Bug Report
Although #4043 has been fixed by #4045, it has adverse impact on performance. It results in multiple modules being checked unnecessarily.

To repeat the example from #4043:

# a.py
import b
b.f()

# b.py
def f() -> None: pass

# b.py (2)
def f(x) -> None: pass

In my own project, I have 27 modules in a single SCC, and mypy takes 26 seconds to analyze if any of them has reported errors. Same if I run mypy again without changing any of the modules. mypy is deleting all 27 cache files!
By the way, if I turn off error reporting on all these modules, then mypy does not delete the cache files. If I then enable error reporting on any one of them which has errors, mypy correctly reports the errors, using the existing cache files, but still deletes the cache files afterward.

I assert that #4045 is the wrong solution, and the cache files should not be deleted in this case. You can remove the following code from build.py\write_cache():

        is_errors = self.transitive_error
        if is_errors:
            delete_cache(self.id, self.path, self.manager)
            self.meta = None
            self.mark_interface_stale(on_errors=True)
            return

This is the only use of transitive_error, so you can remove all references to that elsewhere in the code.

Experiment

I removes the above mentioned code, and added a line if 'a' in scc: fresh = False, which treats module a as stale.
I repeated the calls to mypy cited in #4043, and this time got the expected results every time.

Proposed Fix
Let Sa be the State for module a, and Sb be the State for module b (if it exists).
Sa.is_fresh() needs to recognize that it is out of date with respect to Sb.
Since both modules could be in the same SCC, one meta file will be later than the other, so using mtime is not the answer.
Instead, each meta file Sa should keep some data about each Sb at the time Sa was stored, so that it can detect if this is different from the current Sb in the filesystem. This could be a hash of the metadata, excluding the information for the Sb's.

Your Environment

  • Mypy version used: 0.930
  • Mypy command-line flags: -i
  • Python version used: 3.7
  • Operating system and version: Win 10
@mrolle45 mrolle45 added the bug mypy got something wrong label Mar 15, 2022
@henzef
Copy link

henzef commented Jun 24, 2024

This seems to be still an issue and slows down mypy a lot on my codebase.

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-incremental
Projects
None yet
Development

No branches or pull requests

3 participants