Skip to content

Instantly share code, notes, and snippets.

@domdfcoding
Created June 19, 2020 17:49
Show Gist options
  • Save domdfcoding/63d69230339b6cbe9eebb4201b3db694 to your computer and use it in GitHub Desktop.
Save domdfcoding/63d69230339b6cbe9eebb4201b3db694 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# stdlib
import ast
from typing import Any, Dict, List, Tuple
class Visitor(ast.NodeVisitor):
def __init__(self) -> None:
self.errors: List[Tuple[int, int, str]] = []
self._from_imports: Dict[str, str] = {}
def visit_FunctionDef(self, node: ast.FunctionDef) -> Any:
"""
A docstring
:param node: The node being visited
:type node: ast.FunctionDef
:rtype: None
"""
if node.body and isinstance(node.body[0], ast.Expr):
print(node.body[0])
print(node.body[0].value.s)
print(node.body[0].lineno)
print(node.body[0].col_offset)
input(">")
if __name__ == '__main__':
import pathlib
visitor = Visitor()
visitor.visit(ast.parse(pathlib.Path(__file__).read_text()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment