Skip to content

Commit adbae7b

Browse files
committed
Code review
1 parent 3f6ca36 commit adbae7b

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

pylint/checkers/refactoring/refactoring_checker.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,22 @@
6161
"subprocess.Popen",
6262
)
6363
)
64+
CALLS_THAT_SHOULD_USE_GENERATOR = frozenset(
65+
# 'any', 'all', definitely should use generator, while 'list', 'tuple',
66+
# 'sum', 'max', and 'min' need to be considered first
67+
# See https://github.com/pylint-dev/pylint/pull/3309#discussion_r576683109
68+
# https://github.com/pylint-dev/pylint/pull/6595#issuecomment-1125704244
69+
# and https://peps.python.org/pep-0289/
70+
(
71+
"any",
72+
"all",
73+
"sum",
74+
"max",
75+
"min",
76+
"list",
77+
"tuple",
78+
)
79+
)
6480

6581

6682
def _if_statement_is_always_returning(
@@ -982,8 +998,8 @@ def visit_ifexp(self, node: nodes.IfExp) -> None:
982998
def _check_simplifiable_ifexp(self, node: nodes.IfExp) -> None:
983999
match node:
9841000
case nodes.IfExp(
985-
body=nodes.Const(value=bool() as bval),
986-
orelse=nodes.Const(value=bool() as oval),
1001+
body=nodes.Const(value=bool() as body_value),
1002+
orelse=nodes.Const(value=bool() as orelse_value),
9871003
):
9881004
pass
9891005
case _:
@@ -994,7 +1010,7 @@ def _check_simplifiable_ifexp(self, node: nodes.IfExp) -> None:
9941010
else:
9951011
test_reduced_to = "bool(test)"
9961012

997-
match (bval, oval):
1013+
match (body_value, orelse_value):
9981014
case [True, False]:
9991015
reduced_to = f"'{test_reduced_to}'"
10001016
case [False, True]:
@@ -1098,16 +1114,10 @@ def _check_consider_using_comprehension_constructor(self, node: nodes.Call) -> N
10981114
self.add_message(message_name, node=node)
10991115

11001116
def _check_consider_using_generator(self, node: nodes.Call) -> None:
1101-
# 'any', 'all', definitely should use generator, while 'list', 'tuple',
1102-
# 'sum', 'max', and 'min' need to be considered first
1103-
# See https://github.com/pylint-dev/pylint/pull/3309#discussion_r576683109
1104-
# https://github.com/pylint-dev/pylint/pull/6595#issuecomment-1125704244
1105-
# and https://peps.python.org/pep-0289/
1106-
checked_call = {"any", "all", "sum", "max", "min", "list", "tuple"}
11071117
match node:
11081118
case nodes.Call(
11091119
func=nodes.Name(name=call_name), args=[nodes.ListComp() as comp]
1110-
) if (call_name in checked_call):
1120+
) if (call_name in CALLS_THAT_SHOULD_USE_GENERATOR):
11111121
# functions in checked_calls take exactly one positional argument
11121122
# check whether the argument is list comprehension
11131123
pass

0 commit comments

Comments
 (0)