What is ast.FunctionDef in Python?
Python ast module
The ast module
Python comes with abstract syntax grammar that is subject to change with every Python release.
This module helps applications process syntax trees and find out what the current syntax grammar looks like programmatically.
Abstract syntax trees are great tools for program analysis and program transformation systems.
ast.FunctionDef method
ast.FunctionDef(name, args, body, decorator_list, returns, type_comment) is a class defined in the ast module that expresses a function definition in Python. It expresses the definition in the form of an Abstract Syntax Tree.
When the parse() method of ast is called on a Python source code containing a function definition, it invokes the ast.FunctionDef class. This expresses the function definition to a node in an ast tree data structure.
Parameters
-
namerepresents the function name. -
argsis an argument that contains the function’s arguments. -
bodyis the function body represented by a list of nodes. -
decorator_listis the list of decorators that are to be applied. Decorators are stored outermost first, i.e., the first decorator in the list is applied last. -
returnsis the return annotation. -
type_commentis an optional string that represents the type annotation as a comment.