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

Function _find_strings

Lib/trace.py:353–374  ·  view source on GitHub ↗

Return a dict of possible docstring positions. The dict maps line numbers to strings. There is an entry for line that contains only a string or a part of a triple-quoted string.

(filename, encoding=None)

Source from the content-addressed store, hash-verified

351 return linenos
352
353def _find_strings(filename, encoding=None):
354 """Return a dict of possible docstring positions.
355
356 The dict maps line numbers to strings. There is an entry for
357 line that contains only a string or a part of a triple-quoted
358 string.
359 """
360 d = {}
361 # If the first token is a string, then it's the module docstring.
362 # Add this special case so that the test in the loop passes.
363 prev_ttype = token.INDENT
364 with open(filename, encoding=encoding) as f:
365 tok = tokenize.generate_tokens(f.readline)
366 for ttype, tstr, start, end, line in tok:
367 if ttype == token.STRING:
368 if prev_ttype == token.INDENT:
369 sline, scol = start
370 eline, ecol = end
371 for i in range(sline, eline + 1):
372 d[i] = 1
373 prev_ttype = ttype
374 return d
375
376def _find_executable_linenos(filename):
377 """Return dict where keys are line numbers in the line number table."""

Callers 1

_find_executable_linenosFunction · 0.85

Calls 1

openFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…