[issue46980] ast.FunctionDef cannot find functions under if statement

2022-03-10 Thread Ruishi
Ruishi added the comment: I see. It's my misunderstanding. Thank you for your help! -- ___ Python tracker ___ ___ Python-bugs-list

[issue46980] ast.FunctionDef cannot find functions under if statement

2022-03-10 Thread Jelle Zijlstra
Jelle Zijlstra added the comment: This is the right place to file an issue. Your code is incorrect; it will find only top-level functions. Functions within an `if` statement will be nested inside an `ast.If` node. To find all functions in a file, you'll need to recurse into nested nodes. For

[issue46980] ast.FunctionDef cannot find functions under if statement

2022-03-10 Thread Ruishi
Ruishi added the comment: I'm not sure whether I should file this issue here or on Github and I'm not an expert on this so I think I cannot contribute to this but only report to you. -- ___ Python tracker _

[issue46980] ast.FunctionDef cannot find functions under if statement

2022-03-10 Thread Ruishi
New submission from Ruishi : 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 = [