Skip to content

Commit a30dd4b

Browse files
committed
implement review suggestions
1 parent 9393480 commit a30dd4b

5 files changed

Lines changed: 20 additions & 46 deletions

File tree

pylint/checkers/nested_min_max.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,22 @@
99
import copy
1010
from typing import TYPE_CHECKING
1111

12-
from astroid import nodes
12+
from astroid import nodes, objects
1313

1414
from pylint.checkers import BaseChecker
15-
from pylint.checkers.utils import DICT_TYPES, only_required_for_messages, safe_infer
15+
from pylint.checkers.utils import only_required_for_messages, safe_infer
1616
from pylint.interfaces import INFERENCE
1717

1818
if TYPE_CHECKING:
1919
from pylint.lint import PyLinter
2020

21+
DICT_TYPES = (
22+
objects.DictValues,
23+
objects.DictKeys,
24+
objects.DictItems,
25+
nodes.node_classes.Dict,
26+
)
27+
2128

2229
class NestedMinMaxChecker(BaseChecker):
2330
"""Multiple nested min/max calls on the same line will raise multiple messages.

pylint/checkers/utils.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,6 @@
238238
{"_sitebuiltins.Quitter", "sys.exit", "posix._exit", "nt._exit"}
239239
)
240240

241-
DICT_TYPES = (
242-
astroid.objects.DictValues,
243-
astroid.objects.DictKeys,
244-
astroid.objects.DictItems,
245-
astroid.nodes.node_classes.Dict,
246-
)
247-
248241

249242
class NoSuchArgumentError(Exception):
250243
pass

pylint/checkers/variables.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,13 @@
108108
}
109109
)
110110

111+
DICT_TYPES = (
112+
astroid.objects.DictValues,
113+
astroid.objects.DictKeys,
114+
astroid.objects.DictItems,
115+
astroid.nodes.node_classes.Dict,
116+
)
117+
111118

112119
class VariableVisitConsumerAction(Enum):
113120
"""Reported by _check_consumer() and its sub-methods to determine the
@@ -159,7 +166,7 @@ def _get_unpacking_extra_info(node: nodes.Assign, inferred: InferenceResult) ->
159166
and unbalanced-tuple/dict-unpacking errors.
160167
"""
161168
more = ""
162-
if isinstance(inferred, utils.DICT_TYPES):
169+
if isinstance(inferred, DICT_TYPES):
163170
if isinstance(node, nodes.Assign):
164171
more = node.value.as_string()
165172
elif isinstance(node, nodes.For):
@@ -1242,7 +1249,7 @@ def visit_for(self, node: nodes.For) -> None:
12421249
targets = node.target.elts
12431250

12441251
inferred = utils.safe_infer(node.iter)
1245-
if not isinstance(inferred, utils.DICT_TYPES):
1252+
if not isinstance(inferred, DICT_TYPES):
12461253
return
12471254

12481255
values = self._nodes_to_unpack(inferred)
@@ -2879,7 +2886,7 @@ def _check_unpacking(
28792886
@staticmethod
28802887
def _nodes_to_unpack(node: nodes.NodeNG) -> list[nodes.NodeNG] | None:
28812888
"""Return the list of values of the `Assign` node."""
2882-
if isinstance(node, (nodes.Tuple, nodes.List) + utils.DICT_TYPES):
2889+
if isinstance(node, (nodes.Tuple, nodes.List) + DICT_TYPES):
28832890
return node.itered() # type: ignore[no-any-return]
28842891
if isinstance(node, astroid.Instance) and any(
28852892
ancestor.qname() == "typing.NamedTuple" for ancestor in node.ancestors()
@@ -2905,7 +2912,7 @@ def _report_unbalanced_unpacking(
29052912

29062913
symbol = (
29072914
"unbalanced-dict-unpacking"
2908-
if isinstance(inferred, utils.DICT_TYPES)
2915+
if isinstance(inferred, DICT_TYPES)
29092916
else "unbalanced-tuple-unpacking"
29102917
)
29112918
self.add_message(symbol, node=node, args=args, confidence=INFERENCE)

tests/regrtest_data/nested_min_max.py

Lines changed: 0 additions & 18 deletions
This file was deleted.

tests/test_self.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1302,21 +1302,6 @@ def test_no_name_in_module(self) -> None:
13021302
[module, "-E"], expected_output="", unexpected_output=unexpected
13031303
)
13041304

1305-
def test_nested_min_max_splats(self) -> None:
1306-
"""Test that the nested-min-max message suggests to splat an iterable"""
1307-
module = join(HERE, "regrtest_data", "nested_min_max.py")
1308-
expected_str = f"""
1309-
************* Module nested_min_max
1310-
{module}:4:0: W3301: Do not use nested call of 'max'; it's possible to do 'max(3, *lst)' instead (nested-min-max)
1311-
{module}:7:0: W3301: Do not use nested call of 'max'; it's possible to do 'max(3, *nums)' instead (nested-min-max)
1312-
{module}:10:0: W3301: Do not use nested call of 'max'; it's possible to do 'max(3, *nums)' instead (nested-min-max)
1313-
{module}:13:0: W3301: Do not use nested call of 'max'; it's possible to do 'max(3, *nums)' instead (nested-min-max)
1314-
{module}:15:0: W3301: Do not use nested call of 'max'; it's possible to do 'max(3, *nums.values())' instead (nested-min-max)
1315-
{module}:18:0: W3301: Do not use nested call of 'max'; it's possible to do 'max(3, *nums, *lst2)' instead (nested-min-max)
1316-
""" # noqa: E501
1317-
expected = textwrap.dedent(expected_str)
1318-
self._test_output([module], expected_output=expected)
1319-
13201305

13211306
class TestCallbackOptions:
13221307
"""Test for all callback options we support."""

0 commit comments

Comments
 (0)