inspect_function
logger = logging.getLogger(__name__)
module-attribute
¶
helper functions
FunctionInspector
dataclass
¶
The FunctionInspector does two different loading steps.
- Load all the specs from disk with
get_specs
. This happens once on creation of the object. - On initialization, and before every spec call, go through all the specs and "parse" any for modules we have already imported, which means turning the criteria into in memory objects, we can compare against when inspecting.
Source code in lineapy/execution/inspect_function.py
313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|
inspect(function, args, kwargs, result)
¶
Inspects a function and returns how calling it mutates the args/result and creates view relationships between them.
Source code in lineapy/execution/inspect_function.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|
FunctionInspectorParsed
dataclass
¶
Contains the parsed function inspector criteria.
Source code in lineapy/execution/inspect_function.py
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 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 253 254 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 |
|
add_annotations(module, annotations)
¶
Parse a list of annotations and look them up to add them to our parsed criteria.
Source code in lineapy/execution/inspect_function.py
259 260 261 262 263 264 265 266 267 268 |
|
inspect(fn, kwargs)
¶
Inspect a function call and return a list of side effects, if it matches any of the annotations
Source code in lineapy/execution/inspect_function.py
220 221 222 223 224 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 253 254 255 256 257 |
|
get_imported_module(name)
¶
Return a module, if it has been imported.
Also handles the corner case where a submodule has not been imported, but is accessible
as an attribute on the parent module. This is needed for the example tensorflow.keras.utils
, which
is not imported when importing tensorflow
, but is accessible as a property of tensorflow
.
Source code in lineapy/execution/inspect_function.py
373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 |
|
get_specs()
¶
yaml specs are for non-built in functions. Captures all the .annotations.yaml files in the lineapy directory.
Source code in lineapy/execution/inspect_function.py
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 |
|
is_mutable(obj)
¶
Returns true if the object is mutable.
Note that currently, tempfile.NamedTemporaryFile()
is not mutable, and
the semantics is actually correct, because it doesn't end up changing the
file system. However, the following registers as normal files (which
are mutable).
filename = NamedTemporaryFile().name
handle = open(filename, "wb")
Source code in lineapy/execution/inspect_function.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
|
new_side_effect_without_all_positional_arg(side_effect, args)
¶
This method must NOT modify the original side_effect, since these annotations are dependent on the runtime values that are different for each call — AllPositionalArgs will have a different set of arguments.
Note that we might need to add something like "all keyword arguments", but that use case hasn't come up yet.
Source code in lineapy/execution/inspect_function.py
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
|
validate(item)
¶
We cannot filer the specs by module, because it might be loaded later. This causes a bit of inefficiency in our function inspection, but we can fix later if it's a problem.
Source code in lineapy/execution/inspect_function.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|