61
61
"subprocess.Popen" ,
62
62
)
63
63
)
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
+ )
64
80
65
81
66
82
def _if_statement_is_always_returning (
@@ -982,8 +998,8 @@ def visit_ifexp(self, node: nodes.IfExp) -> None:
982
998
def _check_simplifiable_ifexp (self , node : nodes .IfExp ) -> None :
983
999
match node :
984
1000
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 ),
987
1003
):
988
1004
pass
989
1005
case _:
@@ -994,7 +1010,7 @@ def _check_simplifiable_ifexp(self, node: nodes.IfExp) -> None:
994
1010
else :
995
1011
test_reduced_to = "bool(test)"
996
1012
997
- match (bval , oval ):
1013
+ match (body_value , orelse_value ):
998
1014
case [True , False ]:
999
1015
reduced_to = f"'{ test_reduced_to } '"
1000
1016
case [False , True ]:
@@ -1098,16 +1114,10 @@ def _check_consider_using_comprehension_constructor(self, node: nodes.Call) -> N
1098
1114
self .add_message (message_name , node = node )
1099
1115
1100
1116
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" }
1107
1117
match node :
1108
1118
case nodes .Call (
1109
1119
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 ):
1111
1121
# functions in checked_calls take exactly one positional argument
1112
1122
# check whether the argument is list comprehension
1113
1123
pass
0 commit comments