def get_binding(name, namespace): if name in namespace.global_names and not isinstance( namespace, ast.Module): return get_binding(name, get_global_namespace(namespace)) elif name in namespace.nonlocal_names and not isinstance( namespace, ast.Module): return get_binding(name, get_nonlocal_namespace(namespace)) for binding in namespace.bindings: if binding.name == name: return binding if not isinstance(namespace, ast.Module): return get_binding(name, get_nonlocal_namespace(namespace)) else: # This is unresolved at global scope - is it a builtin? if name in dir(builtins): if name in ['exec', 'eval', 'locals', 'globals', 'vars']: namespace.tainted = True binding = BuiltinBinding(name, namespace, rename_cost=len(name) + 1) namespace.bindings.append(binding) return binding else: binding = NameBinding(name) binding.disallow_rename() namespace.bindings.append(binding) return binding
def get_binding(self, name, namespace): if name in namespace.global_names and not isinstance( namespace, ast.Module): return self.get_binding(name, get_global_namespace(namespace)) elif name in namespace.nonlocal_names and not isinstance( namespace, ast.Module): return self.get_binding(name, get_nonlocal_namespace(namespace)) if isinstance(namespace, ast.ClassDef): binding = self.get_binding(name, get_nonlocal_namespace(namespace)) binding.disallow_rename() return binding for binding in namespace.bindings: if binding.name == name: break else: # weeee! binding = NameBinding(name) namespace.bindings.append(binding) if name in dir(builtins): binding.disallow_rename() if name in namespace.nonlocal_names and isinstance( namespace, ast.Module): # This is actually a syntax error - but we want the same syntax error after minifying! binding.disallow_rename() return binding
def get_binding(self, name, namespace): if name in namespace.global_names and not isinstance( namespace, ast.Module): return self.get_binding(name, get_global_namespace(namespace)) elif name in namespace.nonlocal_names: return self.get_binding(name, get_nonlocal_namespace(namespace)) if isinstance(namespace, ast.ClassDef): binding = self.get_binding(name, get_nonlocal_namespace(namespace)) binding.disallow_rename() return binding for binding in namespace.bindings: if binding.name == name: return binding binding = NameBinding(name) namespace.bindings.append(binding) if name in dir(builtins): binding.disallow_rename() return binding