-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Delete cache for a module if errors are found #4045
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1165,6 +1165,24 @@ def write_cache(id: str, path: str, tree: MypyFile, | |
return interface_hash | ||
|
||
|
||
def delete_cache(id: str, path: str, manager: BuildManager) -> None: | ||
"""Delete cache files for a module. | ||
|
||
The cache files for a module are deleted when mypy finds errors there. | ||
This avoids inconsistent states with cache files from different mypy runs, | ||
see #4043 for an example. | ||
""" | ||
path = os.path.abspath(path) | ||
meta_json, data_json = get_cache_names(id, path, manager) | ||
manager.log('Deleting {} {} {} {}'.format(id, path, meta_json, data_json)) | ||
|
||
for filename in [data_json, meta_json]: | ||
try: | ||
os.remove(filename) | ||
except OSError: | ||
manager.log("Error deleting cache file {}".format(filename)) | ||
|
||
|
||
"""Dependency manager. | ||
|
||
Design | ||
|
@@ -1813,6 +1831,7 @@ def write_cache(self) -> None: | |
else: | ||
is_errors = self.manager.errors.is_errors() | ||
if is_errors: | ||
delete_cache(self.id, self.path, self.manager) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this also mark the interface as stale (as below on line 1845-1847) and set self.interface_hash to something unmatchable? Otherwise I worry we could still repro the same issues by adding another chain to the reference link. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, you are right. I even have found a longer crasher with four files that still happens unless interface is marked as stale (I added it to the tests). Do we also need to set the It looks like marking files with errors as stale breaks several tests. I will check if this can be fixed somehow. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm, there is an explicit comment in tests:
Should I just mark them as stale now and update this comment? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, I think the comment just reflects the state of the world at the time (i.e. that no cache file was written). I presume this only affects some of the tests and not all tests with a Alternatively you could have a flag to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It affects 42 tests, i.e. around one third of all tests with [stale].
OK, I did this. Now all tests should pass. By the way, what do you think about potential performance issues because of this change? Intuitively it should be minor (since it only affects situations where new errors appear after previous incremental runs), but maybe you could measure it somehow? |
||
return | ||
dep_prios = [self.priorities.get(dep, PRI_HIGH) for dep in self.dependencies] | ||
new_interface_hash = write_cache( | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would cause a bit noisy logging. If the file doesn't exist I'd rather not log anything (or specifically log that the file doesn't exist).