beam: fix shadow_lint outer_line always 0 (record binding lines)
This commit is contained in:
1 parent
38996e8cf3
commit
daf30cde0c
1 file changed
+11
-11
@@ -94,11 +94,11 @@ class ShadowFinder(ast.NodeVisitor):
|
||||
# shadow check against enclosing
|
||||
if arg.arg in self._enclosing_bindings():
|
||||
self.shadows.append(Shadow(arg.arg, self.scope.outer_line_for(arg.arg), node.lineno, "function-param"))
|
||||
new_scope.record(arg.arg)
|
||||
new_scope.record(arg.arg, node.lineno)
|
||||
if node.args.vararg:
|
||||
new_scope.record(node.args.vararg.arg)
|
||||
new_scope.record(node.args.vararg.arg, node.lineno)
|
||||
if node.args.kwarg:
|
||||
new_scope.record(node.args.kwarg.arg)
|
||||
new_scope.record(node.args.kwarg.arg, node.lineno)
|
||||
self.generic_visit(node)
|
||||
self.scope = old
|
||||
|
||||
@@ -128,7 +128,7 @@ class ShadowFinder(ast.NodeVisitor):
|
||||
for name in _binding_names(t):
|
||||
if name in self._enclosing_bindings():
|
||||
self.shadows.append(Shadow(name, self.scope.outer_line_for(name), node.lineno, "assignment"))
|
||||
self.scope.bindings.add(name)
|
||||
self.scope.record(name, node.lineno)
|
||||
self.generic_visit(node)
|
||||
|
||||
def visit_AnnAssign(self, node):
|
||||
@@ -136,7 +136,7 @@ class ShadowFinder(ast.NodeVisitor):
|
||||
name = node.target.id
|
||||
if name in self._enclosing_bindings():
|
||||
self.shadows.append(Shadow(name, self.scope.outer_line_for(name), node.lineno, "assignment"))
|
||||
self.scope.bindings.add(name)
|
||||
self.scope.record(name, node.lineno)
|
||||
self.generic_visit(node)
|
||||
|
||||
def visit_AugAssign(self, node):
|
||||
@@ -148,7 +148,7 @@ class ShadowFinder(ast.NodeVisitor):
|
||||
name = alias.asname if alias.asname else alias.name.split(".")[0]
|
||||
if name in self._enclosing_bindings():
|
||||
self.shadows.append(Shadow(name, self.scope.outer_line_for(name), node.lineno, "import"))
|
||||
self.scope.bindings.add(name)
|
||||
self.scope.record(name, node.lineno)
|
||||
self.generic_visit(node)
|
||||
|
||||
def visit_ImportFrom(self, node):
|
||||
@@ -158,14 +158,14 @@ class ShadowFinder(ast.NodeVisitor):
|
||||
name = alias.asname if alias.asname else alias.name
|
||||
if name in self._enclosing_bindings():
|
||||
self.shadows.append(Shadow(name, self.scope.outer_line_for(name), node.lineno, "import"))
|
||||
self.scope.bindings.add(name)
|
||||
self.scope.record(name, node.lineno)
|
||||
self.generic_visit(node)
|
||||
|
||||
def visit_For(self, node):
|
||||
for name in _binding_names(node.target):
|
||||
if name in self._enclosing_bindings():
|
||||
self.shadows.append(Shadow(name, self.scope.outer_line_for(name), node.lineno, "loop-target"))
|
||||
self.scope.bindings.add(name)
|
||||
self.scope.record(name, node.lineno)
|
||||
# body in same scope
|
||||
self.generic_visit(node)
|
||||
|
||||
@@ -178,14 +178,14 @@ class ShadowFinder(ast.NodeVisitor):
|
||||
for name in _binding_names(item.optional_vars):
|
||||
if name in self._enclosing_bindings():
|
||||
self.shadows.append(Shadow(name, self.scope.outer_line_for(name), node.lineno, "with-as"))
|
||||
self.scope.bindings.add(name)
|
||||
self.scope.record(name, node.lineno)
|
||||
self.generic_visit(node)
|
||||
|
||||
def visit_ExceptHandler(self, node):
|
||||
if node.name:
|
||||
if node.name in self._enclosing_bindings():
|
||||
self.shadows.append(Shadow(node.name, self.scope.outer_line_for(node.name), node.lineno, "except-as"))
|
||||
self.scope.bindings.add(node.name)
|
||||
self.scope.record(node.name, node.lineno)
|
||||
self.generic_visit(node)
|
||||
|
||||
# comprehensions create their own scope
|
||||
@@ -209,7 +209,7 @@ class ShadowFinder(ast.NodeVisitor):
|
||||
# shadow relative to enclosing (parent of comp scope)
|
||||
if name in self._enclosing_bindings():
|
||||
self.shadows.append(Shadow(name, self.scope.outer_line_for(name), gen.target.lineno if hasattr(gen.target, "lineno") else node.lineno, "comprehension"))
|
||||
new_scope.bindings.add(name)
|
||||
new_scope.record(name, gen.target.lineno if hasattr(gen.target, "lineno") else node.lineno)
|
||||
# visit body with this scope
|
||||
# for ListComp/SetComp/GenExp: elt; DictComp: key/value
|
||||
if isinstance(node, ast.DictComp):
|
||||
|
||||
Reference in new issue
Block a user