Return a dictionary mapping line numbers to comments in the source code.
(source)
| 439 | |
| 440 | |
| 441 | def 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 | |
| 455 | class GettextVisitor(ast.NodeVisitor): |
no test coverage detected
searching dependent graphs…