Skip to content
Open
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
2 changes: 2 additions & 0 deletions custom_dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ asynccontextmanager
attr
attrib
attrname
attrs
backport
BaseChecker
basename
Expand Down Expand Up @@ -144,6 +145,7 @@ gv
hashable
hmac
html
iattrs
idgeneratormixin
ifexpr
igetattr
Expand Down
4 changes: 4 additions & 0 deletions doc/whatsnew/fragments/10745.false_positive
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Fix a false positive for ``invalid-name`` on an UPPER_CASED name inside an
``if`` branch that assigns an object.

Closes #10745
13 changes: 6 additions & 7 deletions pylint/checkers/base/name_checker/checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,13 +518,12 @@ def visit_assignname( # pylint: disable=too-many-branches,too-many-statements
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)
for combo in itertools.combinations(iattrs, 2)
)
# Do the exclusive assignment analysis on attrs, not iattrs.
# iattrs locations could be anywhere (inference result).
attrs = tuple(node.frame().getattr(node.name))
if len(attrs) > 1 and all(
astroid.are_exclusive(*combo)
for combo in itertools.combinations(attrs, 2)
):
node_type = "const"
if not self._meets_exception_for_non_consts(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ def A(): # [invalid-name]
other_const = [3]


if CONST:
ANOTHER_CONST = A()
else:
ANOTHER_CONST = 5


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

Expand Down