Skip to content

Commit

Permalink
classes too
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoGorelli committed Jan 7, 2025
1 parent 3f83df4 commit b168801
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions utils/remove_docstring_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,23 @@ def visit_FunctionDef(self, node: ast.FunctionDef) -> None: # noqa: N802

self.generic_visit(node)

def visit_ClassDef(self, node: ast.ClassDef) -> None: # noqa: N802
if (
node.body
and isinstance(expr := node.body[0], ast.Expr)
and isinstance(value := expr.value, ast.Constant)
and isinstance(docstring := value.value, str)
and "Examples:" in docstring
and value.end_lineno is not None
):
examples_line_start = value.lineno + [
line.strip() for line in docstring.splitlines()
].index("Examples:")
examples_line_end = value.end_lineno
self.to_remove.append((examples_line_start, examples_line_end))

self.generic_visit(node)


if __name__ == "__main__":
files = sys.argv[1:]
Expand Down

0 comments on commit b168801

Please sign in to comment.