summaryrefslogtreecommitdiff
path: root/pylint
diff options
context:
space:
mode:
authorDani Alcala <112832187+clavedeluna@users.noreply.github.com>2023-02-08 18:03:41 -0300
committerGitHub <noreply@github.com>2023-02-08 22:03:41 +0100
commit29684fe0123335fe1906b079f5cdfc2d0250e021 (patch)
treede04ad8b0a4fcc613c08ddefd5d8c8a8397dfbe0 /pylint
parent7fd499a903348955cbe120b058659f1fa6a29f1a (diff)
downloadpylint-git-29684fe0123335fe1906b079f5cdfc2d0250e021.tar.gz
Fix `nested-min-max` output msg for sequences (#8234)
Diffstat (limited to 'pylint')
-rw-r--r--pylint/checkers/nested_min_max.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/pylint/checkers/nested_min_max.py b/pylint/checkers/nested_min_max.py
index 39feb5f42..e9aa409f0 100644
--- a/pylint/checkers/nested_min_max.py
+++ b/pylint/checkers/nested_min_max.py
@@ -9,7 +9,7 @@ from __future__ import annotations
import copy
from typing import TYPE_CHECKING
-from astroid import nodes
+from astroid import nodes, objects
from pylint.checkers import BaseChecker
from pylint.checkers.utils import only_required_for_messages, safe_infer
@@ -18,6 +18,13 @@ from pylint.interfaces import INFERENCE
if TYPE_CHECKING:
from pylint.lint import PyLinter
+DICT_TYPES = (
+ objects.DictValues,
+ objects.DictKeys,
+ objects.DictItems,
+ nodes.node_classes.Dict,
+)
+
class NestedMinMaxChecker(BaseChecker):
"""Multiple nested min/max calls on the same line will raise multiple messages.
@@ -83,6 +90,20 @@ class NestedMinMaxChecker(BaseChecker):
redundant_calls = self.get_redundant_calls(fixed_node)
+ for idx, arg in enumerate(fixed_node.args):
+ if not isinstance(arg, nodes.Const):
+ inferred = safe_infer(arg)
+ if isinstance(
+ inferred, (nodes.List, nodes.Tuple, nodes.Set, *DICT_TYPES)
+ ):
+ splat_node = nodes.Starred(lineno=inferred.lineno)
+ splat_node.value = arg
+ fixed_node.args = (
+ fixed_node.args[:idx]
+ + [splat_node]
+ + fixed_node.args[idx + 1 : idx]
+ )
+
self.add_message(
"nested-min-max",
node=node,