Skip to content

Commit 0a2225b

Browse files
authored
[dmypy] sort list of files for update by extension (#17245)
dmypy receives the list of updated files via `--update` flag. If this list contains both `foo.py` and `foo.pyi`, the order matters. It seems to process the first file in the list first. But if we have a `.pyi` file, we want this to be processed first since this one contains the typing information. Let's reverse sort the list of updated files by the extension. This should be a simple enough fix to resolve this. Though there might be some edge cases where the list of files to update contains just pyi files, but we might need to recheck the equivalent py files even if not explicitly updated.
1 parent b4f9869 commit 0a2225b

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

mypy/dmypy_server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,9 @@ def cmd_recheck(
383383
removals = set(remove)
384384
sources = [s for s in sources if s.path and s.path not in removals]
385385
if update:
386+
# Sort list of file updates by extension, so *.pyi files are first.
387+
update.sort(key=lambda f: os.path.splitext(f)[1], reverse=True)
388+
386389
known = {s.path for s in sources if s.path}
387390
added = [p for p in update if p not in known]
388391
try:

0 commit comments

Comments
 (0)