From 82b25b9a96e9bb8ba5ff0833eea1a2da3daf77c2 Mon Sep 17 00:00:00 2001 From: Sagexd08 Date: Mon, 7 Sep 2026 22:48:40 +0530 Subject: [PATCH] fix(extract): make _TsRangeIndex a real type alias The alias was written as a quoted string, which makes it a `str` *value* rather than a type. Type checkers reject it: mypy reports "Variable _TsRangeIndex is not valid as a type" at both annotation sites, plus two cascading errors where the tuple loses its type and the unpacking/indexing in _ts_ranges_containing and _normalize_ts_import_types become untyped. `typing.get_type_hints` happened to resolve it at runtime because it evaluates the annotation string and then the alias string again, so nothing failed in practice -- but that is an accident of double evaluation, not a working alias. Unquote the right-hand side. The module already has `from __future__ import annotations`, so the annotations themselves need no quoting either. No behavior change. (cherry picked from commit d902820ccfa534bd20ff7de386ba6addf8f5663a) --- graphify/extract.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/graphify/extract.py b/graphify/extract.py index b57bc7719..8c358761b 100644 --- a/graphify/extract.py +++ b/graphify/extract.py @@ -1363,13 +1363,14 @@ def _ts_type_argument_ranges(root: Any, *, call_only: bool) -> list[tuple[int, i # Sorted type-argument ranges prepared for lookup: (starts, spans, prefix_max_end). -# See _ts_build_range_index. -_TsRangeIndex = "tuple[list[int], list[tuple[int, int]], list[int]]" +# See _ts_build_range_index. A real alias, not a string: quoting the right-hand +# side would make this a `str` value, which type checkers reject as a type. +_TsRangeIndex = tuple[list[int], list[tuple[int, int]], list[int]] def _ts_ranges_containing( - ranges: "_TsRangeIndex", offset: int -) -> "list[tuple[int, int]]": + ranges: _TsRangeIndex, offset: int +) -> list[tuple[int, int]]: """Return the ranges in ``ranges`` that contain ``offset``. Scanning the full range list for every match made @@ -1397,7 +1398,7 @@ def _ts_ranges_containing( return hits -def _ts_build_range_index(root: Any, *, call_only: bool) -> "_TsRangeIndex": +def _ts_build_range_index(root: Any, *, call_only: bool) -> _TsRangeIndex: """Index :func:`_ts_type_argument_ranges` for :func:`_ts_ranges_containing`. Returns the ranges sorted by start, split into a bare ``starts`` list for