Skip to content

Commit

Permalink
rename Flake8TrioVisitor to Flake8AsyncVisitor
Browse files Browse the repository at this point in the history
  • Loading branch information
jakkdl committed Feb 23, 2024
1 parent f42a832 commit 94810a6
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 53 deletions.
8 changes: 4 additions & 4 deletions flake8_trio/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
from libcst import Module

from .base import Error, Options
from .visitors.flake8triovisitor import Flake8TrioVisitor, Flake8TrioVisitor_cst
from .visitors.flake8triovisitor import Flake8AsyncVisitor, Flake8AsyncVisitor_cst


@dataclass
Expand Down Expand Up @@ -73,7 +73,7 @@ def visit(self, node: ast.AST):
"""Visit a node."""
# tracks the subclasses that, from this node on, iterated through it's subfields
# we need to remember it so we can restore it at the end of the function.
novisit: set[Flake8TrioVisitor] = set()
novisit: set[Flake8AsyncVisitor] = set()

method = "visit_" + node.__class__.__name__

Expand Down Expand Up @@ -122,14 +122,14 @@ def __init__(self, options: Options, module: Module):

# Could possibly enable/disable utility visitors here, if visitors declared
# dependencies
self.utility_visitors: tuple[Flake8TrioVisitor_cst, ...] = tuple(
self.utility_visitors: tuple[Flake8AsyncVisitor_cst, ...] = tuple(
v(self.state) for v in utility_visitors
)

# sort the error classes to get predictable behaviour when multiple autofixers
# are enabled
sorted_error_classes_cst = sorted(ERROR_CLASSES_CST, key=lambda x: x.__name__)
self.visitors: tuple[Flake8TrioVisitor_cst, ...] = tuple(
self.visitors: tuple[Flake8AsyncVisitor_cst, ...] = tuple(
v(self.state)
for v in sorted_error_classes_cst
if self.selected(v.error_codes)
Expand Down
10 changes: 5 additions & 5 deletions flake8_trio/visitors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from typing import TYPE_CHECKING

if TYPE_CHECKING:
from .flake8triovisitor import Flake8TrioVisitor, Flake8TrioVisitor_cst
from .flake8triovisitor import Flake8AsyncVisitor, Flake8AsyncVisitor_cst

__all__ = [
"ERROR_CLASSES",
Expand All @@ -19,11 +19,11 @@
"utility_visitors",
"utility_visitors_cst",
]
ERROR_CLASSES: set[type[Flake8TrioVisitor]] = set()
ERROR_CLASSES_CST: set[type[Flake8TrioVisitor_cst]] = set()
ERROR_CLASSES: set[type[Flake8AsyncVisitor]] = set()
ERROR_CLASSES_CST: set[type[Flake8AsyncVisitor_cst]] = set()
default_disabled_error_codes: list[str] = []
utility_visitors: set[type[Flake8TrioVisitor]] = set()
utility_visitors_cst: set[type[Flake8TrioVisitor_cst]] = set()
utility_visitors: set[type[Flake8AsyncVisitor]] = set()
utility_visitors_cst: set[type[Flake8AsyncVisitor_cst]] = set()

# Import all visitors so their decorators run, filling the above containers
# This has to be done at the end to avoid circular imports
Expand Down
6 changes: 3 additions & 3 deletions flake8_trio/visitors/flake8triovisitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
ERROR_CODE_LEN = 8


class Flake8TrioVisitor(ast.NodeVisitor, ABC):
class Flake8AsyncVisitor(ast.NodeVisitor, ABC):
# abstract attribute by not providing a value
error_codes: Mapping[str, str]

Expand All @@ -39,7 +39,7 @@ def __init__(self, shared_state: SharedState):

# mark variables that shouldn't be saved/loaded in self.get_state
self.nocopy = {
"_Flake8TrioVisitor__state",
"_Flake8AsyncVisitor__state",
"error_codes",
"nocopy",
"novisit",
Expand Down Expand Up @@ -158,7 +158,7 @@ def add_library(self, name: str) -> None:
self.__state.library = (*self.__state.library, name)


class Flake8TrioVisitor_cst(cst.CSTTransformer, ABC):
class Flake8AsyncVisitor_cst(cst.CSTTransformer, ABC):
# abstract attribute by not providing a value
error_codes: Mapping[str, str]
METADATA_DEPENDENCIES = (PositionProvider,)
Expand Down
12 changes: 8 additions & 4 deletions flake8_trio/visitors/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,16 @@
if TYPE_CHECKING:
from collections.abc import Iterable, Iterator, Sequence

from .flake8triovisitor import Flake8TrioVisitor, Flake8TrioVisitor_cst, HasLineCol
from .flake8triovisitor import (
Flake8AsyncVisitor,
Flake8AsyncVisitor_cst,
HasLineCol,
)

T = TypeVar("T", bound=Flake8TrioVisitor)
T_CST = TypeVar("T_CST", bound=Flake8TrioVisitor_cst)
T = TypeVar("T", bound=Flake8AsyncVisitor)
T_CST = TypeVar("T_CST", bound=Flake8AsyncVisitor_cst)
T_EITHER = TypeVar(
"T_EITHER", bound=Union[Flake8TrioVisitor, Flake8TrioVisitor_cst]
"T_EITHER", bound=Union[Flake8AsyncVisitor, Flake8AsyncVisitor_cst]
)


Expand Down
4 changes: 2 additions & 2 deletions flake8_trio/visitors/visitor100.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import libcst as cst
import libcst.matchers as m

from .flake8triovisitor import Flake8TrioVisitor_cst
from .flake8triovisitor import Flake8AsyncVisitor_cst
from .helpers import (
AttributeCall,
error_class_cst,
Expand All @@ -26,7 +26,7 @@


@error_class_cst
class Visitor100_libcst(Flake8TrioVisitor_cst):
class Visitor100_libcst(Flake8AsyncVisitor_cst):
error_codes: Mapping[str, str] = {
"ASYNC100": (
"{0}.{1} context contains no checkpoints, remove the context or add"
Expand Down
4 changes: 2 additions & 2 deletions flake8_trio/visitors/visitor101.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from typing import TYPE_CHECKING, Any

from .flake8triovisitor import Flake8TrioVisitor_cst
from .flake8triovisitor import Flake8AsyncVisitor_cst
from .helpers import (
cancel_scope_names,
error_class_cst,
Expand All @@ -23,7 +23,7 @@


@error_class_cst
class Visitor101(Flake8TrioVisitor_cst):
class Visitor101(Flake8AsyncVisitor_cst):
error_codes: Mapping[str, str] = {
"ASYNC101": (
"`yield` inside a nursery or cancel scope is only safe when implementing "
Expand Down
4 changes: 2 additions & 2 deletions flake8_trio/visitors/visitor102.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
from typing import TYPE_CHECKING, Any

from ..base import Statement
from .flake8triovisitor import Flake8TrioVisitor
from .flake8triovisitor import Flake8AsyncVisitor
from .helpers import cancel_scope_names, critical_except, error_class, get_matching_call

if TYPE_CHECKING:
from collections.abc import Mapping


@error_class
class Visitor102(Flake8TrioVisitor):
class Visitor102(Flake8AsyncVisitor):
error_codes: Mapping[str, str] = {
"ASYNC102": (
"await inside {0.name} on line {0.lineno} must have shielded cancel "
Expand Down
4 changes: 2 additions & 2 deletions flake8_trio/visitors/visitor103_104.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import ast
from typing import TYPE_CHECKING, Any

from .flake8triovisitor import Flake8TrioVisitor
from .flake8triovisitor import Flake8AsyncVisitor
from .helpers import critical_except, error_class, iter_guaranteed_once

if TYPE_CHECKING:
Expand All @@ -36,7 +36,7 @@


@error_class
class Visitor103_104(Flake8TrioVisitor):
class Visitor103_104(Flake8AsyncVisitor):
error_codes: Mapping[str, str] = _error_codes

def __init__(self, *args: Any, **kwargs: Any):
Expand Down
4 changes: 2 additions & 2 deletions flake8_trio/visitors/visitor105.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ast
from typing import TYPE_CHECKING, Any

from .flake8triovisitor import Flake8TrioVisitor
from .flake8triovisitor import Flake8AsyncVisitor
from .helpers import error_class

if TYPE_CHECKING:
Expand Down Expand Up @@ -42,7 +42,7 @@


@error_class
class Visitor105(Flake8TrioVisitor):
class Visitor105(Flake8AsyncVisitor):
error_codes: Mapping[str, str] = {
"ASYNC105": "{0} async {1} must be immediately awaited.",
}
Expand Down
4 changes: 2 additions & 2 deletions flake8_trio/visitors/visitor111.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import ast
from typing import TYPE_CHECKING, Any, NamedTuple

from .flake8triovisitor import Flake8TrioVisitor
from .flake8triovisitor import Flake8AsyncVisitor
from .helpers import error_class, get_matching_call

if TYPE_CHECKING:
from collections.abc import Mapping


@error_class
class Visitor111(Flake8TrioVisitor):
class Visitor111(Flake8AsyncVisitor):
error_codes: Mapping[str, str] = {
"ASYNC111": (
"variable {2} is usable within the context manager on line {0}, but that "
Expand Down
4 changes: 2 additions & 2 deletions flake8_trio/visitors/visitor118.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
import re
from typing import TYPE_CHECKING

from .flake8triovisitor import Flake8TrioVisitor
from .flake8triovisitor import Flake8AsyncVisitor
from .helpers import error_class

if TYPE_CHECKING:
from collections.abc import Mapping


@error_class
class Visitor118(Flake8TrioVisitor):
class Visitor118(Flake8AsyncVisitor):
error_codes: Mapping[str, str] = {
"ASYNC118": (
"Don't assign the value of `anyio.get_cancelled_exc_class()` to a variable,"
Expand Down
4 changes: 2 additions & 2 deletions flake8_trio/visitors/visitor2xx.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
import re
from typing import TYPE_CHECKING, Any

from .flake8triovisitor import Flake8TrioVisitor
from .flake8triovisitor import Flake8AsyncVisitor
from .helpers import error_class, fnmatch_qualified_name, get_matching_call

if TYPE_CHECKING:
from collections.abc import Mapping


@error_class
class Visitor200(Flake8TrioVisitor):
class Visitor200(Flake8AsyncVisitor):
error_codes: Mapping[str, str] = {
"ASYNC200": (
"User-configured blocking sync call {0} in async function, consider "
Expand Down
4 changes: 2 additions & 2 deletions flake8_trio/visitors/visitor91x.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from libcst.metadata import PositionProvider

from ..base import Statement
from .flake8triovisitor import Flake8TrioVisitor_cst
from .flake8triovisitor import Flake8AsyncVisitor_cst
from .helpers import (
disabled_by_default,
error_class_cst,
Expand Down Expand Up @@ -226,7 +226,7 @@ def leave_Yield(

@error_class_cst
@disabled_by_default
class Visitor91X(Flake8TrioVisitor_cst, CommonVisitors):
class Visitor91X(Flake8AsyncVisitor_cst, CommonVisitors):
error_codes: Mapping[str, str] = {
"ASYNC910": (
"{0} from async function with no guaranteed checkpoint or exception "
Expand Down
12 changes: 6 additions & 6 deletions flake8_trio/visitors/visitor_utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import libcst.matchers as m
from libcst.metadata import PositionProvider

from .flake8triovisitor import Flake8TrioVisitor, Flake8TrioVisitor_cst
from .flake8triovisitor import Flake8AsyncVisitor, Flake8AsyncVisitor_cst
from .helpers import utility_visitor, utility_visitor_cst

if TYPE_CHECKING:
Expand All @@ -21,7 +21,7 @@


@utility_visitor
class VisitorTypeTracker(Flake8TrioVisitor):
class VisitorTypeTracker(Flake8AsyncVisitor):
def visit_AsyncFunctionDef(
self, node: ast.AsyncFunctionDef | ast.FunctionDef | ast.Lambda
):
Expand Down Expand Up @@ -101,15 +101,15 @@ def visit_With(self, node: ast.With | ast.AsyncWith):


@utility_visitor
class VisitorAwaitModifier(Flake8TrioVisitor):
class VisitorAwaitModifier(Flake8AsyncVisitor):
def visit_Await(self, node: ast.Await):
if isinstance(node.value, ast.Call):
# add attribute to indicate it's awaited
setattr(node.value, "awaited", True) # noqa: B010


@utility_visitor
class VisitorLibraryHandler(Flake8TrioVisitor):
class VisitorLibraryHandler(Flake8AsyncVisitor):
def __init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs)
# check whether library we're working towards has been explicitly
Expand All @@ -126,7 +126,7 @@ def visit_Import(self, node: ast.Import):


@utility_visitor_cst
class VisitorLibraryHandler_cst(Flake8TrioVisitor_cst):
class VisitorLibraryHandler_cst(Flake8AsyncVisitor_cst):
def __init__(self, *args: Any, **kwargs: Any):
super().__init__(*args, **kwargs)
# check whether library we're working towards has been explicitly
Expand Down Expand Up @@ -172,7 +172,7 @@ def _find_noqa(physical_line: str) -> Match[str] | None:


@utility_visitor_cst
class NoqaHandler(Flake8TrioVisitor_cst):
class NoqaHandler(Flake8AsyncVisitor_cst):
def visit_Comment(self, node: cst.Comment):
noqa_match = _find_noqa(node.value)
if noqa_match is None:
Expand Down
Loading

0 comments on commit 94810a6

Please sign in to comment.