Skip to content

Commit

Permalink
[#3791] address code review
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Jul 22, 2021
1 parent aff1218 commit d987fe0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTORS.txt
@@ -1,4 +1,4 @@
Contributors
Contributors
------------

Current team:
Expand Down
19 changes: 7 additions & 12 deletions pylint/checkers/variables.py
Expand Up @@ -945,8 +945,6 @@ def visit_delname(self, node):

def visit_name(self, node):
"""Check that a name is defined in the current scope"""
# refactoring this block is a pain.
# pylint: disable=too-many-nested-blocks,too-many-branches
stmt = node.statement()
if stmt.fromlineno is None:
# name node from an astroid built from live code, skip
Expand All @@ -966,7 +964,7 @@ def visit_name(self, node):

# iterates through parent scopes, from the inner to the outer
base_scope_type = self._to_consume[start_index].scope_type

# pylint: disable=too-many-nested-blocks; refactoring this block is a pain.
for i in range(start_index, -1, -1):
current_consumer = self._to_consume[i]

Expand Down Expand Up @@ -1009,21 +1007,18 @@ def visit_name(self, node):
# variable used outside the loop
# avoid the case where there are homonyms inside function scope and
# comprehension current scope (avoid bug #1731)
if name in current_consumer.consumed and not (
current_consumer.scope_type == "comprehension"
and self._has_homonym_in_upper_function_scope(node, i)
if name in current_consumer.consumed and (
utils.is_func_decorator(current_consumer.node)
or not (
current_consumer.scope_type == "comprehension"
and self._has_homonym_in_upper_function_scope(node, i)
)
):
defnode = utils.assign_parent(current_consumer.consumed[name][0])
self._check_late_binding_closure(node, defnode)
self._loopvar_name(node, name)
break

# the name has already been consumed, skip decorators
if name in current_consumer.consumed and utils.is_func_decorator(
current_consumer.node
):
break

found_node = current_consumer.get_next_to_consume(node)
if found_node is None:
continue
Expand Down

0 comments on commit d987fe0

Please sign in to comment.