MCPcopy Index your code
hub / github.com/python/cpython / Span

Class Span

Lib/_pyrepl/utils.py:32–54  ·  view source on GitHub ↗

Span indexing that's inclusive on both ends.

Source from the content-addressed store, hash-verified

30
31
32class Span(NamedTuple):
33 """Span indexing that's inclusive on both ends."""
34
35 start: int
36 end: int
37
38 @classmethod
39 def from_re(cls, m: Match[str], group: int | str) -> Self:
40 re_span = m.span(group)
41 return cls(re_span[0], re_span[1] - 1)
42
43 @classmethod
44 def from_token(cls, token: TI, line_len: list[int]) -> Self:
45 end_offset = -1
46 if (token.type in {T.FSTRING_MIDDLE, T.TSTRING_MIDDLE}
47 and token.string.endswith(("{", "}"))):
48 # gh-134158: a visible trailing brace comes from a double brace in input
49 end_offset += 1
50
51 return cls(
52 line_len[token.start[0] - 1] + token.start[1],
53 line_len[token.end[0] - 1] + token.end[1] + end_offset,
54 )
55
56
57class ColorSpan(NamedTuple):

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…