New submission from Ruishi <summerlinas...@gmail.com>:
When I use the Python ast package to get the functions of Python files, I find the functions defined in the body of `if` statement cannot be recognized. Here is my code: with open(py_file, 'r') as f: data = f.read() module = ast.parse(data) func_def = [node for node in module.body if isinstance(node, ast.FunctionDef)] Here is an example of Python file: if supports_bytes_environ: def _check_bytes(value): if not isinstance(value, bytes): raise TypeError("bytes expected, not %s" % type(value).__name__) return value The function `_check_bytes` is not in `func_def`. I also tested `ast.iter_child_nodes(module)` and it also has this issue. ---------- components: Parser messages: 414886 nosy: Ruishi, lys.nikolaou, pablogsal priority: normal severity: normal status: open title: ast.FunctionDef cannot find functions under if statement type: enhancement versions: Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue46980> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com