PyFunction class

Represents a user-defined function declared using the def keyword or the expression body of al lambdafunction.

It stores the function's definition (declaration) from the AST and captures the lexical environment (closure) where the function was defined. This closure is used to resolve non-local variables when the function is called.

Constructors

PyFunction.fromDef(FunctionStmt declaration, Environment closure, {bool isInitializer = false})
Constructor for DEF function
PyFunction.fromLambda(LambdaExpr lambdaExpr, Environment closure)

Properties

closure → Environment
The environment that was active when the function was defined. This enables lexical scoping (closures).
final
declaration → FunctionStmt?
The AST node representing the function definition (def name(...) ...).
final
expressionBody → Expr?
expression in case of lambda function
final
hashCode → int
The hash code for this object.
no setterinherited
isInitializer → bool
Flag indicating if this function is an initializer (e.g., __init__ if classes were supported).
final
params → List<Parameter>
parameters of function declaration or lambda function
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

bind(PyInstance instance) → PyBoundMethod
Creates a PyBoundMethod instance linking this function to a receiver instance.
call(Interpreter interpreter, List<Object?> positionalArgs, Map<String, Object?> keywordArgs, {PyInstance? receiver}) → Object?
Executes the user-defined function.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
inherited