Skip to content

Commit 934ec50

Browse files
CoolCat467sterliakov
authored andcommitted
Lessen dmypy suggest path limitations for Windows machines (#19337)
In this pull request, we allow dmypy suggest absolute paths to contain the drive letter colon for Windows machines. Fixes #19335. This is done by changing how `find_node` works slightly, allowing there to be at most two colon (`:`) characters in the passed key for windows machines instead of just one like on all other platforms, and then using `rsplit` and a split limit of 1 instead of just `split` like prior. --------- Co-authored-by: Stanislav Terliakov <[email protected]>
1 parent a4801f9 commit 934ec50

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

mypy/suggestions.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import itertools
2828
import json
2929
import os
30+
import sys
3031
from collections.abc import Iterator
3132
from contextlib import contextmanager
3233
from typing import Callable, NamedTuple, TypedDict, TypeVar, cast
@@ -537,12 +538,17 @@ def find_node(self, key: str) -> tuple[str, str, FuncDef]:
537538
# TODO: Also return OverloadedFuncDef -- currently these are ignored.
538539
node: SymbolNode | None = None
539540
if ":" in key:
540-
if key.count(":") > 1:
541+
# A colon might be part of a drive name on Windows (like `C:/foo/bar`)
542+
# and is also used as a delimiter between file path and lineno.
543+
# If a colon is there for any of those reasons, it must be a file+line
544+
# reference.
545+
platform_key_count = 2 if sys.platform == "win32" else 1
546+
if key.count(":") > platform_key_count:
541547
raise SuggestionFailure(
542548
"Malformed location for function: {}. Must be either"
543549
" package.module.Class.method or path/to/file.py:line".format(key)
544550
)
545-
file, line = key.split(":")
551+
file, line = key.rsplit(":", 1)
546552
if not line.isdigit():
547553
raise SuggestionFailure(f"Line number must be a number. Got {line}")
548554
line_number = int(line)

0 commit comments

Comments
 (0)