def _check_nonlocal_and_global(self, node):
def same_scope(current):<EOL><INDENT>return current.scope() is node<EOL><DEDENT>from_iter = itertools.chain.from_iterable<EOL>nonlocals = set(<EOL>from_iter(<EOL>child.names<EOL>for child in node.nodes_of_class(astroid.Nonlocal)<EOL>if same_scope(child)<EOL>)<EOL>)<EOL>if not nonlocals:<EOL><INDENT>return<EOL><DEDENT>global_vars = set(<EOL>from_iter(<EOL>child.names<EOL>for child in node.nodes_of_class(astroid.Global)<EOL>if same_scope(child)<EOL>)<EOL>)<EOL>for name in nonlocals.intersection(global_vars):<EOL><INDENT>self.add_message("<STR_LIT>", args=(name,), node=node)<EOL><DEDENT>
Check that a name is both nonlocal and global.