Message414886
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. |
|
Date |
User |
Action |
Args |
2022-03-11 03:08:56 | Ruishi | set | recipients:
+ Ruishi, lys.nikolaou, pablogsal |
2022-03-11 03:08:56 | Ruishi | set | messageid: <1646968136.79.0.973896459669.issue46980@roundup.psfhosted.org> |
2022-03-11 03:08:56 | Ruishi | link | issue46980 messages |
2022-03-11 03:08:56 | Ruishi | create | |
|