Python ast.Nonlocal() Examples

The following are 5 code examples of ast.Nonlocal(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module ast , or try the search function .
Example #1
Source File: _343.py    From codetransformer with GNU General Public License v2.0 6 votes vote down vote up
def make_global_and_nonlocal_decls(code_instrs):
    """
    Find all STORE_GLOBAL and STORE_DEREF instructions in `instrs` and convert
    them into a canonical list of `ast.Global` and `ast.Nonlocal` declarations.
    """
    globals_ = sorted(set(
        i.arg for i in code_instrs if isinstance(i, instrs.STORE_GLOBAL)
    ))
    nonlocals = sorted(set(
        i.arg for i in code_instrs
        if isinstance(i, instrs.STORE_DEREF) and i.vartype == 'free'
    ))

    out = []
    if globals_:
        out.append(ast.Global(names=globals_))
    if nonlocals:
        out.append(ast.Nonlocal(names=nonlocals))
    return out 
Example #2
Source File: symbol_analyzer.py    From YAPyPy with MIT License 5 votes vote down vote up
def _visit_nonlocal(self, node: ast.Nonlocal):
    self.symtable.explicit_nonlocals.update(node.names)
    return node 
Example #3
Source File: test_ast.py    From Fluid-Designer with GNU General Public License v3.0 5 votes vote down vote up
def test_nonlocal(self):
        self.stmt(ast.Nonlocal([]), "empty names on Nonlocal") 
Example #4
Source File: test_ast.py    From ironpython3 with Apache License 2.0 5 votes vote down vote up
def test_nonlocal(self):
        self.stmt(ast.Nonlocal([]), "empty names on Nonlocal") 
Example #5
Source File: test_ast.py    From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 5 votes vote down vote up
def test_nonlocal(self):
        self.stmt(ast.Nonlocal([]), "empty names on Nonlocal")