Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 10 additions & 6 deletions lsp/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -1477,7 +1477,7 @@ def visit(node):
return best[0]


def _meta_in_file(meta, path: str) -> bool:
def _meta_in_file(meta: Any, path: str) -> bool:
"""True iff ``meta``'s source file is ``path``.

Compares the ``filename`` attribute the parsers stash on each
Expand All @@ -1491,7 +1491,7 @@ def _meta_in_file(meta, path: str) -> bool:
import os

fname = getattr(meta, "filename", None)
if fname is None or fname == "???":
if not isinstance(fname, str) or fname == "???":
# No reliable file info on this node. Don't reject -- some
# synthetic nodes never get a filename, and rejecting them
# outright would regress same-file lookups.
Expand All @@ -1504,15 +1504,19 @@ def _meta_in_file(meta, path: str) -> bool:
return False


def _meta_span(meta) -> int:
def _meta_span(meta: Any) -> int:
"""Crude size measure for a ``Meta``; smaller wins ties in tree
descent so inner nodes outrank enclosing ones."""
if meta.line == meta.end_line:
return meta.end_column - meta.column
line = int(meta.line)
end_line = int(meta.end_line)
column = int(meta.column)
end_column = int(meta.end_column)
if line == end_line:
return end_column - column
# Multi-line ranges are larger than any single-line range. Use a
# huge per-line cost so we never pick a multi-line Var over a
# single-line one that contains the cursor.
return 10_000 * (meta.end_line - meta.line) + meta.end_column
return 10_000 * (end_line - line) + end_column


def _find_declaration(ast_nodes, target_name: str, _seen=None):
Expand Down
7 changes: 7 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -196,3 +196,10 @@ module = ["parser"]
disallow_any_generics = true
disallow_untyped_calls = true
warn_return_any = true

# lsp/query.py is being ratcheted in #506. This slice enforces concrete
# returns for annotated helpers; the remaining strict bits are larger
# follow-up passes.
[[tool.mypy.overrides]]
module = ["lsp.query"]
warn_return_any = true
Loading