diff options
author | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-10-18 14:58:01 +0200 |
---|---|---|
committer | Daniël van Noord <13665637+DanielNoord@users.noreply.github.com> | 2021-10-18 16:03:44 +0200 |
commit | 1daee40d6f1cf3d379396dc272c123d987ad4cdd (patch) | |
tree | 9aba810d362eade68a6c4715236483183dfc4b8a /pylint | |
parent | 816c8f8c7badc9355628c3eb0e455650dc1f99ef (diff) | |
download | pylint-git-1daee40d6f1cf3d379396dc272c123d987ad4cdd.tar.gz |
Make ``undefined-variable`` check line numbers of metaclass parameters
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/checkers/variables.py | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index ef53f19cb..1d78184c8 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -2213,23 +2213,30 @@ class VariablesChecker(BaseChecker): elif metaclass: name = metaclass.root().name - found = None + found = False name = METACLASS_NAME_TRANSFORMS.get(name, name) if name: # check enclosing scopes starting from most local for scope_locals, _, _ in self._to_consume[::-1]: - found = scope_locals.get(name) - if found: - consumed.append((scope_locals, name)) + found_nodes = scope_locals.get(name, []) + for found_node in found_nodes: + if found_node.lineno <= klass.lineno: + consumed.append((scope_locals, name)) + found = True + break + # Check parent scope + nodes_in_parent_scope = parent_node.locals.get(name, []) + for found_node_parent in nodes_in_parent_scope: + if found_node_parent.lineno <= klass.lineno: + found = True break if ( - found is None + not found and not metaclass and not ( name in nodes.Module.scope_attrs or utils.is_builtin(name) or name in self.config.additional_builtins - or name in parent_node.locals ) ): self.add_message("undefined-variable", node=klass, args=(name,)) |