From adeccb46b3964afb23dd85baa4533f4b6f892fab Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Tue, 24 Jun 2025 19:20:40 -0500 Subject: [PATCH 1/2] Allow dmypy suggest paths to contain drive letter colon in Windows machines Fixes #19335 --- mypy/suggestions.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mypy/suggestions.py b/mypy/suggestions.py index 81eb20bd0ac3..56789b7f8dc2 100644 --- a/mypy/suggestions.py +++ b/mypy/suggestions.py @@ -27,6 +27,7 @@ import itertools import json import os +import sys from collections.abc import Iterator from contextlib import contextmanager from typing import Callable, NamedTuple, TypedDict, TypeVar, cast @@ -549,12 +550,13 @@ def find_node(self, key: str) -> tuple[str, str, FuncDef]: # TODO: Also return OverloadedFuncDef -- currently these are ignored. node: SymbolNode | None = None if ":" in key: - if key.count(":") > 1: + platform_key_count = 2 if sys.platform == "win32" else 1 + if key.count(":") > platform_key_count: raise SuggestionFailure( "Malformed location for function: {}. Must be either" " package.module.Class.method or path/to/file.py:line".format(key) ) - file, line = key.split(":") + file, line = key.rsplit(":", 1) if not line.isdigit(): raise SuggestionFailure(f"Line number must be a number. Got {line}") line_number = int(line) From 5281b06b11fdaf9bdf1af04d8928f646de3b4092 Mon Sep 17 00:00:00 2001 From: CoolCat467 <52022020+CoolCat467@users.noreply.github.com> Date: Wed, 25 Jun 2025 21:27:34 -0500 Subject: [PATCH 2/2] Add logic explaination comment Co-authored-by: Stanislav Terliakov <50529348+sterliakov@users.noreply.github.com> --- mypy/suggestions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mypy/suggestions.py b/mypy/suggestions.py index 56789b7f8dc2..45aa5ade47a4 100644 --- a/mypy/suggestions.py +++ b/mypy/suggestions.py @@ -550,6 +550,10 @@ def find_node(self, key: str) -> tuple[str, str, FuncDef]: # TODO: Also return OverloadedFuncDef -- currently these are ignored. node: SymbolNode | None = None if ":" in key: + # A colon might be part of a drive name on Windows (like `C:/foo/bar`) + # and is also used as a delimiter between file path and lineno. + # If a colon is there for any of those reasons, it must be a file+line + # reference. platform_key_count = 2 if sys.platform == "win32" else 1 if key.count(":") > platform_key_count: raise SuggestionFailure(