@@ -74,10 +74,17 @@ def process_data(input_data: str, debug: bool = False):
7474process_data(" test" , debug = True )
7575```
7676
77- You can access the arguments and parameters of the function call:
77+ You can access and modify the arguments and parameters of the function call with APIs detailed below.
78+
79+ ### Finding Arguments
80+
81+ The primary APIs for finding arguments are:
82+
83+ - [ FunctionCall.args] ( /api-reference/core/FunctionCall#args )
84+ - [ FunctionCall.get_arg_by_parameter_name(...)] ( /api-reference/core/FunctionCall#get-arg-by-parameter-name )
85+ - [ FunctionCall.get_arg_by_index(...)] ( /api-reference/core/FunctionCall#get-arg-by-index )
7886
7987``` python
80- # Manipulation code:
8188# Get the function call
8289call = file .function_calls[0 ]
8390
@@ -98,6 +105,53 @@ debug_arg = call.get_arg_by_parameter_name("debug")
98105first_arg = call.get_arg_by_index(0 )
99106```
100107
108+ ### Modifying Arguments
109+
110+ There are two ways to modify function call arguments:
111+
112+ 1 . Using [ FunctionCall.set_kwarg(...)] ( /api-reference/core/FunctionCall#set-kwarg ) to add or modify keyword arguments:
113+
114+ ``` python
115+ # Modifying keyword arguments
116+ call.set_kwarg(" debug" , " False" ) # Modifies existing kwarg
117+ call.set_kwarg(" new_param" , " value" , create_on_missing = True ) # Adds new kwarg
118+ call.set_kwarg(" input_data" , " 'new_value'" , override_existing = True ) # Converts positional to kwarg
119+ ```
120+
121+ 2 . Using [ FuncionCall.args.append(...)] ( /api-reference/core/FunctionCall#args ) to add new arguments:
122+ <Tip >
123+ [ FunctionCall.args] ( /api-reference/core/FunctionCall#args ) is a
124+ [ Collection] ( /building-with-codegen/collections ) of
125+ [ Argument] ( /api-reference/core/Argument ) objects, so it supports
126+ [ .append(...)] ( /api-reference/core/List#append ) ,
127+ [ .insert(...)] ( /api-reference/core/List#insert ) and other collection
128+ methods.
129+ </Tip >
130+
131+ ``` python
132+ # Adding new arguments
133+ call.args.append(' cloud="aws"' ) # Add a new keyword argument
134+ call.args.append(' "value"' ) # Add a new positional argument
135+
136+ # Real-world example: Adding arguments to a decorator
137+ @app.function (image = runner_image)
138+ def my_func ():
139+ pass
140+
141+ # Add cloud and region if not present
142+ if " cloud=" not in decorator.call.source:
143+ decorator.call.args.append(' cloud="aws"' )
144+ if " region=" not in decorator.call.source:
145+ decorator.call.args.append(' region="us-east-1"' )
146+ ```
147+
148+ The ` set_kwarg ` method provides intelligent argument manipulation:
149+
150+ - If the argument exists and is positional, it converts it to a keyword argument
151+ - If the argument exists and is already a keyword, it updates its value (if override_existing=True)
152+ - If the argument doesn't exist, it creates it (if create_on_missing=True)
153+ - When creating new arguments, it intelligently places them based on parameter order
154+
101155Arguments and parameters support safe edit operations like so:
102156
103157``` python
0 commit comments