def check(self, file, unused_checker): names = {} # map name, parent to this scope for node, scope in file.scopes.items(): if hasattr(node, 'name'): # classes, functions key = (scope.parent, node.name) if names.has_key(key): # oops, another scope has the same name and parent first = node second = names[key] # but don't warn if the parent node is the same If or Try if util.try_if_exclusive(first, second): continue if first.lineno > second.lineno: second, first = first, second file.warning(first, self.redefinedScope, first.name, second.lineno) names[key] = node
def add_import(node, local, remote, module): scopes = util.enclosing_scopes(file.scopes, node) for scope in scopes: try: ref = scope.imports[local] if not util.try_if_exclusive(ref.nodes, node): if ref.module == module: if scope == scopes[0]: extra = " in current scope" else: extra = " of import in parent scope %s" % scope file.warning(node, ImportCheck.duplicateImport, local, extra) else: file.warning(node, ImportCheck.shadowImport, local, ref.module.__name__, ref.nodes.lineno) except KeyError: pass scopes[0].imports[local] = ModuleReference(local, remote, module, node) checker.check_module(module)