Skip to content

Commit 328569f

Browse files
Fix FP for invalid-name on module-level constant with multiple branches
1 parent 042717c commit 328569f

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Fix a false positive for ``invalid-name`` on exclusive module-level assignments
2+
composed of three or more branches.
3+
4+
Closes #10664

pylint/checkers/base/name_checker/checker.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -523,8 +523,11 @@ def visit_assignname( # pylint: disable=too-many-branches,too-many-statements
523523
if (
524524
(iattrs := tuple(node.frame().igetattr(node.name)))
525525
and util.Uninferable not in iattrs
526-
and len(iattrs) == 2
527-
and astroid.are_exclusive(*iattrs)
526+
and len(iattrs) > 1
527+
and all(
528+
astroid.are_exclusive(*combo)
529+
for combo in itertools.combinations(iattrs, 2)
530+
)
528531
):
529532
node_type = "const"
530533
self._check_name(

tests/functional/i/invalid/invalid_name/invalid_name_module_level.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ def A(): # [invalid-name]
2828

2929
if CONST:
3030
OTHER_CONST = 1
31-
else:
31+
elif CONSTA:
3232
OTHER_CONST = 2
33+
else:
34+
OTHER_CONST = 3

0 commit comments

Comments
 (0)