Fix file reloading in dmypy with --export-types#16359
Conversation
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
| changed += [ | ||
| (bs.module, bs.path) | ||
| for bs in sources | ||
| if bs.path and (bs.module, bs.path) not in changed |
There was a problem hiding this comment.
This is quadratic, and it could be slow if there are many files and many that are changed. Maybe construct a temporary set from changed and use it in the not in changed check?
There was a problem hiding this comment.
Yes, good point, fixed now.
| changed += [ | ||
| (bs.module, bs.path) | ||
| for bs in sources | ||
| if bs.path and (bs.module, bs.path) not in changed |
There was a problem hiding this comment.
Similar to above. Maybe move this to a helper function to avoid code duplication?
There was a problem hiding this comment.
Moved to a helper function.
| options.use_fine_grained_cache = self.use_cache and not build_cache | ||
| options.cache_fine_grained = self.use_cache | ||
| options.local_partial_types = True | ||
| options.export_types = True |
There was a problem hiding this comment.
What's the purpose of this change?
There was a problem hiding this comment.
Starting the daemon with this option set to True is cleaner for inspect unit tests, I made this explicit now (so it will not slow down other fine grained tests).
|
|
||
| def run_check(self, server: Server, sources: list[BuildSource]) -> list[str]: | ||
| response = server.check(sources, export_types=True, is_tty=False, terminal_width=-1) | ||
| response = server.check(sources, export_types=False, is_tty=False, terminal_width=-1) |
There was a problem hiding this comment.
Hmm why do we have export_types=False here, but true above?
There was a problem hiding this comment.
Passing it explicitly on each run will force reloading files. Putting it in options from the start is IMO cleaner.
|
Diff from mypy_primer, showing the effect of this PR on open source code: discord.py (https://github.com/Rapptz/discord.py): typechecking got 1.09x faster (138.5s -> 127.5s)
(Performance measurements are based on a single noisy sample)
|
Fixes #15794 Unfortunately, this requires to pass `--export-types` to `dmypy run` if one wants to inspect a file that was previously kicked out of the build.
The script format changelog entries based on commit history and has some rules to filter out some changes, such as typeshed sync and changes cherry-picked to the previous release branch. Example of how to run it: ``` $ python misc/generate_changelog.py 1.7 Generating changelog for 1.7 Previous release was 1.6 Merge base: d7b2451 NOTE: Drop "Fix crash on ParamSpec unification (for real)", since it was in previous release branch NOTE: Drop "Fix crash on ParamSpec unification", since it was in previous release branch NOTE: Drop "Fix mypyc regression with pretty", since it was in previous release branch NOTE: Drop "Clear cache when adding --new-type-inference", since it was in previous release branch NOTE: Drop "Match note error codes to import error codes", since it was in previous release branch NOTE: Drop "Make PEP 695 constructs give a reasonable error message", since it was in previous release branch NOTE: Drop "Fix ParamSpec inference for callback protocols", since it was in previous release branch NOTE: Drop "Try upgrading tox", since it was in previous release branch NOTE: Drop "Optimize Unpack for failures", since it was in previous release branch * Fix crash on unpack call special-casing (Ivan Levkivskyi, PR [16381](#16381)) * Fix file reloading in dmypy with --export-types (Ivan Levkivskyi, PR [16359](#16359)) * Fix daemon crash caused by deleted submodule (Jukka Lehtosalo, PR [16370](#16370)) ... ```
Fixes #15794
Unfortunately, this requires to pass
--export-typestodmypy runif one wants to inspect a file that was previously kicked out of the build.