Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/10652.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix false positive for ``invalid-name`` on a partially uninferable module-level constant.

Closes #10652
9 changes: 7 additions & 2 deletions pylint/checkers/base/name_checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -520,9 +520,14 @@ def visit_assignname( # pylint: disable=too-many-branches,too-many-statements
self._check_name("const", node.name, node)
else:
node_type = "variable"
iattrs = tuple(node.frame().igetattr(node.name))
if (
(iattrs := tuple(node.frame().igetattr(node.name)))
and util.Uninferable not in iattrs
util.Uninferable in iattrs
and self._name_regexps["const"].match(node.name) is not None
):
return
if (
util.Uninferable not in iattrs
and len(iattrs) > 1
and all(
astroid.are_exclusive(*combo)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""Tests for invalid name for names declared at module level"""
# pylint: disable=missing-class-docstring, too-few-public-methods, missing-function-docstring
# pylint: disable=missing-class-docstring, too-few-public-methods, missing-function-docstring, wrong-import-position

import collections

Expand Down Expand Up @@ -42,3 +42,12 @@ def A(): # [invalid-name]
other_const = [2]
else:
other_const = [3]


from importlib.metadata import PackageNotFoundError
from importlib.metadata import version

try:
VERSION = version("ty") # uninferable
except PackageNotFoundError:
VERSION = "0.0.0"