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

Function get_source_comments

Tools/i18n/pygettext.py:441–452  ·  view source on GitHub ↗

Return a dictionary mapping line numbers to comments in the source code.

(source)

Source from the content-addressed store, hash-verified

439
440
441def get_source_comments(source):
442 """
443 Return a dictionary mapping line numbers to
444 comments in the source code.
445 """
446 comments = {}
447 for token in tokenize.tokenize(BytesIO(source).readline):
448 if token.type == tokenize.COMMENT:
449 # Remove any leading combination of '#' and whitespace
450 comment = token.string.lstrip('# \t')
451 comments[token.start[0]] = comment
452 return comments
453
454
455class GettextVisitor(ast.NodeVisitor):

Callers 1

visit_fileMethod · 0.85

Calls 2

BytesIOClass · 0.90
lstripMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…