Inheritance: AsyncFunctionDef inherits from FunctionDef and sets its kind to ASTKind.AsyncFunctionDefKind.
Attributes: Uses the same attributes as FunctionDef, representing the function's name, arguments, body, return type, and decorators.
Usage: Represents asynchronous function definitions (e.g., async def foo(): ...).
Additional Considerations
Integration:
Ensure that wherever functions are handled in your AST processing, asynchronous functions (AsyncFunctionDef) are appropriately distinguished from regular functions (FunctionDef).
Update any visitor or transformer classes to handle the new AsyncFunctionDefKind and AwaitExprKind.
Imports:
Make sure to import necessary classes and types, such as Expr, FunctionDef, Arguments, Block, ASTNodes, SourceLocation, and Optional from the appropriate modules.
AST Structure:
The AwaitExpr can be used within the body of an AsyncFunctionDef to represent awaiting asynchronous operations.
The AsyncFunctionDef class allows you to model functions that can use await expressions.
from gpt:
1. Update
ASTKind
Enum inastx/base.py
Add the following lines to your
ASTKind
enumeration to include the newAwaitExprKind
andAsyncFunctionDefKind
:2. Define
AwaitExpr
ClassAdd the following class definition to represent the
AwaitExpr
, likely inastx/expressions.py
:Notes:
AwaitExpr
inherits fromExpr
since it's used where expressions are expected.value
: The expression representing the asynchronous operation to await.await
expressions in asynchronous code (e.g.,await some_async_function()
).3. Define
AsyncFunctionDef
ClassAdd the following class definition to represent an asynchronous function definition, possibly in
astx/callables.py
:Notes:
AsyncFunctionDef
inherits fromFunctionDef
and sets itskind
toASTKind.AsyncFunctionDefKind
.FunctionDef
, representing the function's name, arguments, body, return type, and decorators.async def foo(): ...
).Additional Considerations
AsyncFunctionDef
) are appropriately distinguished from regular functions (FunctionDef
).AsyncFunctionDefKind
andAwaitExprKind
.Expr
,FunctionDef
,Arguments
,Block
,ASTNodes
,SourceLocation
, andOptional
from the appropriate modules.AwaitExpr
can be used within the body of anAsyncFunctionDef
to represent awaiting asynchronous operations.AsyncFunctionDef
class allows you to model functions that can useawait
expressions.