Skip to content

Commit

Permalink
Add Scope type
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdrozd committed Oct 1, 2024
1 parent b41b190 commit 06f6213
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions pylint/checkers/variables.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

if TYPE_CHECKING:
from collections.abc import Generator, Iterable, Iterator
from typing import Literal

from astroid.nodes import _base_nodes
from astroid.typing import InferenceResult
Expand All @@ -42,6 +43,8 @@

Consumption = dict[str, list[nodes.NodeNG]]

Scope = Literal["class", "comprehension", "function", "lambda", "module"]


SPECIAL_OBJ = re.compile("^_{2}[a-z]+_{2}$")
FUTURE = "__future__"
Expand Down Expand Up @@ -478,7 +481,7 @@ class NamesConsumer:
"""A simple class to handle consumed, to consume and scope type info of node locals."""

node: nodes.NodeNG
scope_type: str
scope_type: Scope

to_consume: Consumption
consumed: Consumption
Expand All @@ -492,7 +495,7 @@ class NamesConsumer:
(e.g. for unused-variable) may need to add them back.
"""

def __init__(self, node: nodes.NodeNG, scope_type: str):
def __init__(self, node: nodes.NodeNG, scope_type: Scope):
self.node = node
self.scope_type = scope_type

Expand Down Expand Up @@ -1759,7 +1762,7 @@ def _check_consumer(
stmt: nodes.NodeNG,
frame: nodes.LocalsDictNodeNG,
current_consumer: NamesConsumer,
base_scope_type: str,
base_scope_type: Scope,
) -> tuple[VariableVisitConsumerAction, list[nodes.NodeNG] | None]:
"""Checks a consumer for conditions that should trigger messages."""
# If the name has already been consumed, only check it's not a loop
Expand Down Expand Up @@ -2190,7 +2193,7 @@ def _is_variable_violation(
defstmt: _base_nodes.Statement,
frame: nodes.LocalsDictNodeNG, # scope of statement of node
defframe: nodes.LocalsDictNodeNG,
base_scope_type: str,
base_scope_type: Scope,
is_recursive_klass: bool,
) -> tuple[bool, bool, bool]:
maybe_before_assign = True
Expand Down

0 comments on commit 06f6213

Please sign in to comment.