A docstring is the first STATEMENT in a module/class/function body. A leading `comment` node — the shebang line essentially every executable script starts with, a coding-declaration or license header, or any ordinary comment — is not a statement: tree-sitter still pa
(body_node)
| 2090 | file_nid = _make_id(str(path)) |
| 2091 | |
| 2092 | def _get_docstring(body_node) -> tuple[str, int] | None: |
| 2093 | """A docstring is the first STATEMENT in a module/class/function body. |
| 2094 | |
| 2095 | A leading `comment` node — the shebang line essentially every |
| 2096 | executable script starts with, a coding-declaration or license |
| 2097 | header, or any ordinary comment — is not a statement: tree-sitter |
| 2098 | still parses it as a sibling child of the body, but Python's own |
| 2099 | docstring rule skips right over it. The old unconditional `break` |
| 2100 | after the first loop iteration stopped at that comment instead of |
| 2101 | looking past it, so a module docstring behind a shebang (or any |
| 2102 | leading comment) was silently never found (#3312). |
| 2103 | """ |
| 2104 | if not body_node: |
| 2105 | return None |
| 2106 | for child in body_node.children: |
| 2107 | if child.type == "comment": |
| 2108 | continue |
| 2109 | if child.type == "expression_statement": |
| 2110 | for sub in child.children: |
| 2111 | if sub.type in ("string", "concatenated_string"): |
| 2112 | text = source[sub.start_byte:sub.end_byte].decode("utf-8", errors="replace") |
| 2113 | text = text.strip("\"'").strip('"""').strip("'''").strip() |
| 2114 | if len(text) > 20: |
| 2115 | return text, child.start_point[0] + 1 |
| 2116 | break |
| 2117 | return None |
| 2118 | |
| 2119 | def _add_rationale(text: str, line: int, parent_nid: str) -> None: |
| 2120 | # Normalize whitespace before truncating, not after: slicing raw text |
no outgoing calls
no test coverage detected