(co)
return out_names
Find all globals names read or written to by codeblock co
Find all globals names read or written to by codeblock co
Find all globals names read or written to by codeblock co
def _extract_code_globals(co):
    """
    Find all globals names read or written to by codeblock co
    """
    out_names = _extract_code_globals_cache.get(co)
    if out_names is None:
        names = co.co_names
        out_names = {names[oparg] for _, oparg in _walk_global_ops(co)}

        # Declaring a function inside another one using the "def ..."
        # syntax generates a constant code object corresonding to the one
        # of the nested function's As the nested function may itself need
        # global variables, we need to introspect its code, extract its
        # globals, (look for code object in it's co_consts attribute..) and
        # add the result to code_globals
        if co.co_consts:
            for const in co.co_consts:
                if isinstance(const, types.CodeType):
                    out_names |= _extract_code_globals(const)

        _extract_code_globals_cache[co] = out_names

    return out_names
def _extract_code_globals ( co ) : out_names = _extract_code_globals_cache . get ( co ) if out_names is None : names = co . co_names out_names = { names [ oparg ] for _ , oparg in _walk_global_ops ( co ) } # Declaring a function inside another one using the "def ..." # syntax generates a constant code object corresonding to the one # of the nested function's As the nested function may itself need # global variables, we need to introspect its code, extract its # globals, (look for code object in it's co_consts attribute..) and # add the result to code_globals if co . co_consts : for const in co . co_consts : if isinstance ( const , types . CodeType ) : out_names |= _extract_code_globals ( const ) _extract_code_globals_cache [ co ] = out_names return out_names