Skip to content

Commit 5ef02fa

Browse files
Fix FP for invalid-name on partially uninferable module-level constant
1 parent 6678c90 commit 5ef02fa

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Fix false positive for ``invalid-name`` on a partially uninferable module-level constant.
2+
3+
Closes #10652

pylint/checkers/base/name_checker/checker.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -520,14 +520,15 @@ def visit_assignname( # pylint: disable=too-many-branches,too-many-statements
520520
self._check_name("const", node.name, node)
521521
else:
522522
node_type = "variable"
523+
iattrs = tuple(node.frame().igetattr(node.name))
523524
if (
524-
(iattrs := tuple(node.frame().igetattr(node.name)))
525-
and util.Uninferable not in iattrs
526-
and len(iattrs) > 1
527-
and all(
528-
astroid.are_exclusive(*combo)
529-
for combo in itertools.combinations(iattrs, 2)
530-
)
525+
util.Uninferable in iattrs
526+
and self._name_regexps["const"].match(node.name) is not None
527+
):
528+
return
529+
if len(iattrs) > 1 and all(
530+
astroid.are_exclusive(*combo)
531+
for combo in itertools.combinations(iattrs, 2)
531532
):
532533
node_type = "const"
533534
if not self._meets_exception_for_non_consts(

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,3 +42,11 @@ def A(): # [invalid-name]
4242
other_const = [2]
4343
else:
4444
other_const = [3]
45+
46+
47+
from importlib.metadata import version
48+
49+
try:
50+
VERSION = version("ty") # uninferable
51+
except:
52+
VERSION = "0.0.0"

0 commit comments

Comments
 (0)