Find all globals names read or written to by codeblock co.
(co)
| 311 | |
| 312 | |
| 313 | def _extract_code_globals(co): |
| 314 | """Find all globals names read or written to by codeblock co.""" |
| 315 | out_names = _extract_code_globals_cache.get(co) |
| 316 | if out_names is None: |
| 317 | # We use a dict with None values instead of a set to get a |
| 318 | # deterministic order and avoid introducing non-deterministic pickle |
| 319 | # bytes as a results. |
| 320 | out_names = {name: None for name in _walk_global_ops(co)} |
| 321 | |
| 322 | # Declaring a function inside another one using the "def ..." syntax |
| 323 | # generates a constant code object corresponding to the one of the |
| 324 | # nested function's As the nested function may itself need global |
| 325 | # variables, we need to introspect its code, extract its globals, (look |
| 326 | # for code object in it's co_consts attribute..) and add the result to |
| 327 | # code_globals |
| 328 | if co.co_consts: |
| 329 | for const in co.co_consts: |
| 330 | if isinstance(const, types.CodeType): |
| 331 | out_names.update(_extract_code_globals(const)) |
| 332 | |
| 333 | _extract_code_globals_cache[co] = out_names |
| 334 | |
| 335 | return out_names |
| 336 | |
| 337 | |
| 338 | def _find_imported_submodules(code, top_level_dependencies): |
no test coverage detected
searching dependent graphs…