Skip to content

Commit 8df94d2

Browse files
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 de23d08 commit 8df94d2

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
@@ -549,12 +550,17 @@ def find_node(self, key: str) -> tuple[str, str, FuncDef]:
549550
# TODO: Also return OverloadedFuncDef -- currently these are ignored.
550551
node: SymbolNode | None = None
551552
if ":" in key:
552-
if key.count(":") > 1:
553+
# A colon might be part of a drive name on Windows (like `C:/foo/bar`)
554+
# and is also used as a delimiter between file path and lineno.
555+
# If a colon is there for any of those reasons, it must be a file+line
556+
# reference.
557+
platform_key_count = 2 if sys.platform == "win32" else 1
558+
if key.count(":") > platform_key_count:
553559
raise SuggestionFailure(
554560
"Malformed location for function: {}. Must be either"
555561
" package.module.Class.method or path/to/file.py:line".format(key)
556562
)
557-
file, line = key.split(":")
563+
file, line = key.rsplit(":", 1)
558564
if not line.isdigit():
559565
raise SuggestionFailure(f"Line number must be a number. Got {line}")
560566
line_number = int(line)

0 commit comments

Comments
 (0)