Class Function::Function

A function, independent of defaults and binding. It is the syntactic entity that is compiled to a code object.

Direct supertypes

Indirect supertypes

Known direct subtypes

Predicates

contains

Whether this contains inner syntactically

containsInScope

Whether this contains inner syntactically and inner has the same scope as this

getAChildNode

Gets a child node of this node in the AST. This predicate exists to aid exploration of the AST and other experiments. The child-parent relation may not be meaningful. For a more meaningful relation in terms of dependency use Expr.getASubExpression(), Stmt.getASubStatement(), Stmt.getASubExpression() or Scope.getAStmt().

getADecorator

Gets a decorator of this function

getAKeywordOnlyArg

Gets a keyword-only parameter of this function.

getAStmt

Gets a statement in the function

getArgByName
getArgName

Gets the name of the nth argument (for simple arguments)

getBody

Gets the statements forming the body of this function

getDefinition

The expression defining this function

getEnclosingScope

The scope in which this function occurs, will be a class for a method, another function for nested functions, generator expressions or comprehensions, or a module for a plain function.

getEvaluatingScope

Gets the evaluation scope for code in this (lexical) scope. This is usually the scope itself, but may be an enclosing scope. Notably, for list comprehensions in Python 2.

getFunctionObject

Gets the FunctionObject corresponding to this function

getKeywordOnlyArg

Gets the nth keyword-only parameter of this function.

getKeywordOnlyParameterCount

Gets the number of keyword-only parameters

getLocation

Gets the location for this AST node

getMetrics

Gets the metrics for this function

getName

Gets the name used to define this function

getPositionalParameterCount

Gets the number of positional parameters

getQualifiedName

Gets the qualified name for this function. Should return the same name as the __qualname__ attribute on functions in Python 3.

getScope
getStmt

Gets the nth statement in the function

hasKwArg

Whether this function accepts arbitrary keyword arguments. That is, whether it has a double-starred (**kwarg) parameter.

hasVarArg

Whether this function accepts a variable number of arguments. That is, whether it has a starred (*arg) parameter.

isGenerator

Whether this function is a generator function, that is whether it contains a yield or yield-from expression

isInitMethod

Whether this function is declared in a class and is named “init

isMethod

Whether this function is declared in a class

isProcedure

Whether this function is a procedure, that is, it has no explicit return statement and always returns None. Note that generator and async functions are not procedures as they return generators and coroutines respectively.

isSpecialMethod

Whether this is a special method, that is does its name have the form __xxx__ (except __init__)

toString

Inherited predicates

getAFlowNode

Gets a flow node corresponding directly to this node. NOTE: For some statements and other purely syntactic elements, there may not be a ControlFlowNode

from AstNode
getAKwonlyarg

Gets a keyword-only parameter of this function.

from Function_
getANormalExit

Gets an exit from this Scope’s control flow graph, that does not result from an exception

from Scope
getAnArg

Gets a positional parameter of this function.

from Function_
getAnExitNode

Gets an exit from this Scope’s control flow graph

from Scope
getArg

Gets the nth positional parameter of this function.

from Function_
getArgs

Gets the positional parameter list of this function.

from Function_
getDocString

Gets the docstring for this scope

from Scope
getEnclosingModulefrom Scope
getEntryNode

Gets the entry point into this Scope’s control flow graph

from Scope
getFallthroughNode

Gets the non-explicit exit from this Scope’s control flow graph

from Scope
getKwarg

Gets the dictionary (**) parameter of this function.

from Function_
getKwonlyarg

Gets the nth keyword-only parameter of this function.

from Function_
getKwonlyargs

Gets the keyword-only parameter list of this function.

from Function_
getLastStatementfrom Scope
getParentfrom Function_
getParentNode

Gets the parent node of this node in the AST. This predicate exists to aid exploration of the AST and other experiments. The child-parent relation may not be meaningful. For a more meaningful relation in terms of dependency use Expr.getASubExpression(), Stmt.getASubStatement(), Stmt.getASubExpression() or Scope.getAStmt() applied to the parent.

from AstNode
getReturnNode

Gets the exit of this scope following from a return statement

from Scope
getVararg

Gets the tuple (*) parameter of this function.

from Function_
inSource

Holds if this scope is in the source archive, that is it is part of the code specified, not library code

from Scope
isArtificial

Whether this syntactic element is artificial, that is it is generated by the compiler and is not present in the source

from AstNode
isAsync

Whether the async property of this function is true.

from Function_
isPublic

Holds if this scope is deemed to be public

from Scope
isTopLevel

Holds if this a top-level (non-nested) class or function

from Scope
precedes

Holds if this scope can be expected to execute before other. Modules precede functions and methods in those modules __init__ precedes other methods. __enter__ precedes __exit__. NOTE that this is context-insensitive, so a module “precedes” a function in that module, even if that function is called from the module scope.

from Scope