From 1cbc3d818b2b279747ef8d4222262fea4b21cccb Mon Sep 17 00:00:00 2001 From: Jacob Walls Date: Sat, 29 Apr 2023 14:32:50 -0400 Subject: Fix false negative for calling module-level function before definition (#8494) --- pylint/checkers/variables.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'pylint') diff --git a/pylint/checkers/variables.py b/pylint/checkers/variables.py index 08797c93c..2504c0c84 100644 --- a/pylint/checkers/variables.py +++ b/pylint/checkers/variables.py @@ -218,17 +218,11 @@ def _detect_global_scope( return node.lineno < defframe.lineno # type: ignore[no-any-return] if not isinstance(node.parent, (nodes.FunctionDef, nodes.Arguments)): return False - elif any( - not isinstance(f, (nodes.ClassDef, nodes.Module)) for f in (frame, defframe) - ): - # Not interested in other frames, since they are already - # not in a global scope. - return False break_scopes = [] - for current_scope in (scope, def_scope): + for current_scope in (scope or frame, def_scope): # Look for parent scopes. If there is anything different - # than a module or a class scope, then they frames don't + # than a module or a class scope, then the frames don't # share a global scope. parent_scope = current_scope while parent_scope: @@ -239,7 +233,7 @@ def _detect_global_scope( parent_scope = parent_scope.parent.scope() else: break - if break_scopes and len(set(break_scopes)) != 1: + if len(set(break_scopes)) > 1: # Store different scopes than expected. # If the stored scopes are, in fact, the very same, then it means # that the two frames (frame and defframe) share the same scope, -- cgit v1.2.1