prefect.utilities.callables
¶
Utilities for working with Python callables.
ParameterSchema
¶
Bases: BaseModel
Simple data model corresponding to an OpenAPI Schema
.
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 |
|
dict
¶
Exclude None
fields by default to comply with
the OpenAPI spec.
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
217 218 219 220 221 222 |
|
call_with_parameters
¶
Call a function with parameters extracted with get_call_parameters
The function must have an identical signature to the original function or this
will fail. If you need to send to a function with a different signature, extract
the args/kwargs using parameters_to_positional_and_keyword
directly
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
171 172 173 174 175 176 177 178 179 180 |
|
cloudpickle_wrapped_call
¶
Serializes a function call using cloudpickle then returns a callable which will execute that call and return a cloudpickle serialized return value
This is particularly useful for sending calls to libraries that only use the Python
built-in pickler (e.g. anyio.to_process
and multiprocessing
) but may require
a wider range of pickling support.
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
collapse_variadic_parameters
¶
Given a parameter dictionary, move any parameters stored not present in the signature into the variadic keyword argument.
Example:
```python
def foo(a, b, **kwargs):
pass
parameters = {"a": 1, "b": 2, "c": 3, "d": 4}
collapse_variadic_parameters(foo, parameters)
# {"a": 1, "b": 2, "kwargs": {"c": 3, "d": 4}}
```
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
explode_variadic_parameter
¶
Given a parameter dictionary, move any parameters stored in a variadic keyword argument parameter (i.e. **kwargs) into the top level.
Example:
```python
def foo(a, b, **kwargs):
pass
parameters = {"a": 1, "b": 2, "kwargs": {"c": 3, "d": 4}}
explode_variadic_parameter(foo, parameters)
# {"a": 1, "b": 2, "c": 3, "d": 4}
```
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
get_call_parameters
¶
Bind a call to a function to get parameter/value mapping. Default values on the signature will be included if not overridden.
Raises a ParameterBindError if the arguments/kwargs are not valid for the function
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
|
get_parameter_defaults
¶
Get default parameter values for a callable.
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
parameter_docstrings
¶
Given a docstring in Google docstring format, parse the parameter section and return a dictionary that maps parameter names to docstring.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
docstring |
Optional[str]
|
The function's docstring. |
required |
Returns:
Type | Description |
---|---|
Dict[str, str]
|
Mapping from parameter names to docstrings. |
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
parameter_schema
¶
Given a function, generates an OpenAPI-compatible description of the function's arguments, including: - name - typing information - whether it is required - a default value - additional constraints (like possible enum values)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fn |
function
|
The function whose arguments will be serialized |
required |
Returns:
Name | Type | Description |
---|---|---|
dict |
ParameterSchema
|
the argument schema |
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
parameters_to_args_kwargs
¶
Convert a parameters
dictionary to positional and keyword arguments
The function must have an identical signature to the original function or this will return an empty tuple and dict.
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
|
raise_for_reserved_arguments
¶
Raise a ReservedArgumentError if fn
has any parameters that conflict
with the names contained in reserved_arguments
.
Source code in /home/runner/work/docs/docs/prefect_source/src/prefect/utilities/callables.py
315 316 317 318 319 320 321 322 323 324 |
|