Skip to content

Lessen dmypy suggest path limitations for Windows machines #19337

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions mypy/suggestions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -549,12 +550,17 @@ 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:
# 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(
"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)
Expand Down