Skip to content

Commit fb5ab45

Browse files
committed
Shorten name of ConsumerAction
1 parent 01d0226 commit fb5ab45

File tree

1 file changed

+23
-29
lines changed

1 file changed

+23
-29
lines changed

pylint/checkers/variables.py

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def register(linter: PyLinter) -> None:
7777
linter.register_checker(VariablesChecker(linter))
7878

7979

80-
class VariableVisitConsumerAction(Enum):
80+
class ConsumerAction(Enum):
8181
"""Reported by _check_consumer() and its sub-methods to determine the
8282
subsequent action to take in _undefined_and_used_before_checker().
8383
@@ -670,9 +670,7 @@ def _inferred_to_define_name_raise_or_return(
670670
None,
671671
)
672672
handlers = try_except_node.handlers if try_except_node else []
673-
return _defines_name_raises_or_returns_recursive(
674-
name, node
675-
) or all(
673+
return _defines_name_raises_or_returns_recursive(name, node) or all(
676674
_defines_name_raises_or_returns_recursive(name, handler)
677675
for handler in handlers
678676
)
@@ -1303,9 +1301,9 @@ def _undefined_and_used_before_checker(
13031301
# We check here instead of before every single return in _check_consumer()
13041302
nodes_to_consume += current_consumer.consumed_uncertain[node.name]
13051303
current_consumer.mark_as_consumed(node.name, nodes_to_consume)
1306-
if action is VariableVisitConsumerAction.CONTINUE:
1304+
if action is ConsumerAction.CONTINUE:
13071305
continue
1308-
if action is VariableVisitConsumerAction.RETURN:
1306+
if action is ConsumerAction.RETURN:
13091307
return
13101308

13111309
# we have not found the name, if it isn't a builtin, that's an
@@ -1378,7 +1376,7 @@ def _check_consumer(
13781376
frame: nodes.LocalsDictNodeNG,
13791377
current_consumer: NamesConsumer,
13801378
base_scope_type: str,
1381-
) -> tuple[VariableVisitConsumerAction, list[nodes.NodeNG] | None]:
1379+
) -> tuple[ConsumerAction, list[nodes.NodeNG] | None]:
13821380
"""Checks a consumer for conditions that should trigger messages."""
13831381
# If the name has already been consumed, only check it's not a loop
13841382
# variable used outside the loop.
@@ -1389,11 +1387,11 @@ def _check_consumer(
13891387
node, nodes.ComprehensionScope
13901388
):
13911389
self._check_late_binding_closure(node)
1392-
return (VariableVisitConsumerAction.RETURN, None)
1390+
return (ConsumerAction.RETURN, None)
13931391

13941392
found_nodes = current_consumer.get_next_to_consume(node)
13951393
if found_nodes is None:
1396-
return (VariableVisitConsumerAction.CONTINUE, None)
1394+
return (ConsumerAction.CONTINUE, None)
13971395
if not found_nodes:
13981396
self._report_unfound_name_definition(node, current_consumer)
13991397
# Mark for consumption any nodes added to consumed_uncertain by
@@ -1403,7 +1401,7 @@ def _check_consumer(
14031401
node, nodes_to_consume
14041402
)
14051403
return (
1406-
VariableVisitConsumerAction.RETURN,
1404+
ConsumerAction.RETURN,
14071405
nodes_to_consume,
14081406
)
14091407

@@ -1446,7 +1444,7 @@ def _check_consumer(
14461444
# Also do not consume class name
14471445
# (since consuming blocks subsequent checks)
14481446
# -- quit
1449-
return (VariableVisitConsumerAction.RETURN, None)
1447+
return (ConsumerAction.RETURN, None)
14501448

14511449
(
14521450
maybe_before_assign,
@@ -1464,7 +1462,7 @@ def _check_consumer(
14641462
)
14651463

14661464
if use_outer_definition:
1467-
return (VariableVisitConsumerAction.CONTINUE, None)
1465+
return (ConsumerAction.CONTINUE, None)
14681466

14691467
if (
14701468
maybe_before_assign
@@ -1496,8 +1494,8 @@ def _check_consumer(
14961494
and node.name in node.root().locals
14971495
):
14981496
if defined_by_stmt:
1499-
return (VariableVisitConsumerAction.CONTINUE, [node])
1500-
return (VariableVisitConsumerAction.CONTINUE, None)
1497+
return (ConsumerAction.CONTINUE, [node])
1498+
return (ConsumerAction.CONTINUE, None)
15011499

15021500
elif base_scope_type != "lambda":
15031501
# E0601 may *not* occurs in lambda scope.
@@ -1517,7 +1515,7 @@ def _check_consumer(
15171515
node=node,
15181516
confidence=HIGH,
15191517
)
1520-
return (VariableVisitConsumerAction.RETURN, found_nodes)
1518+
return (ConsumerAction.RETURN, found_nodes)
15211519

15221520
elif base_scope_type == "lambda":
15231521
# E0601 can occur in class-level scope in lambdas, as in
@@ -1552,7 +1550,7 @@ def _check_consumer(
15521550
self.add_message(
15531551
"undefined-variable", args=node.name, node=node, confidence=HIGH
15541552
)
1555-
return (VariableVisitConsumerAction.RETURN, found_nodes)
1553+
return (ConsumerAction.RETURN, found_nodes)
15561554

15571555
elif isinstance(defstmt, nodes.ClassDef):
15581556
return _is_first_level_self_reference(node, defstmt, found_nodes)
@@ -1566,9 +1564,9 @@ def _check_consumer(
15661564
node=node,
15671565
confidence=INFERENCE,
15681566
)
1569-
return (VariableVisitConsumerAction.RETURN, found_nodes)
1567+
return (ConsumerAction.RETURN, found_nodes)
15701568

1571-
return (VariableVisitConsumerAction.RETURN, found_nodes)
1569+
return (ConsumerAction.RETURN, found_nodes)
15721570

15731571
def _report_unfound_name_definition(
15741572
self,
@@ -2726,9 +2724,7 @@ def _uncertain_nodes_in_except_blocks(
27262724
# Assume the except blocks execute, so long as each handler
27272725
# defines the name, raises, or returns.
27282726
elif all(
2729-
_defines_name_raises_or_returns_recursive(
2730-
node.name, handler
2731-
)
2727+
_defines_name_raises_or_returns_recursive(node.name, handler)
27322728
for handler in closest_try_except.handlers
27332729
):
27342730
continue
@@ -2879,9 +2875,7 @@ def _try_in_loop_body(
28792875
return False
28802876

28812877
for loop_stmt in closest_loop.body:
2882-
if _recursive_search_for_continue_before_break(
2883-
loop_stmt, break_stmt
2884-
):
2878+
if _recursive_search_for_continue_before_break(loop_stmt, break_stmt):
28852879
break
28862880
else:
28872881
# No continue found, so we arrived at our special case!
@@ -3301,7 +3295,7 @@ def _is_first_level_self_reference(
33013295
node: nodes.Name,
33023296
defstmt: nodes.ClassDef,
33033297
found_nodes: list[nodes.NodeNG],
3304-
) -> tuple[VariableVisitConsumerAction, list[nodes.NodeNG] | None]:
3298+
) -> tuple[ConsumerAction, list[nodes.NodeNG] | None]:
33053299
"""Check if a first level method's annotation or default values
33063300
refers to its own class, and return a consumer action.
33073301
"""
@@ -3310,14 +3304,14 @@ def _is_first_level_self_reference(
33103304
# Break if postponed evaluation is enabled
33113305
if utils.is_node_in_type_annotation_context(node):
33123306
if not utils.is_postponed_evaluation_enabled(node):
3313-
return (VariableVisitConsumerAction.CONTINUE, None)
3314-
return (VariableVisitConsumerAction.RETURN, None)
3307+
return (ConsumerAction.CONTINUE, None)
3308+
return (ConsumerAction.RETURN, None)
33153309
# Check if used as default value by calling the class
33163310
if isinstance(node.parent, nodes.Call) and isinstance(
33173311
node.parent.parent, nodes.Arguments
33183312
):
3319-
return (VariableVisitConsumerAction.CONTINUE, None)
3320-
return (VariableVisitConsumerAction.RETURN, found_nodes)
3313+
return (ConsumerAction.CONTINUE, None)
3314+
return (ConsumerAction.RETURN, found_nodes)
33213315

33223316

33233317
def _is_never_evaluated(

0 commit comments

Comments
 (0)