mirror of
https://github.com/safishamsi/graphify.git
synced 2026-10-14 07:59:40 +00:00
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 d902820ccf)
This commit is contained in:
1 parent
1dcb1e1f3a
commit
82b25b9a96
1 file changed
+6
-5
+6
-5
@@ -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
|
||||
|
||||
Reference in new issue
Block a user