diff --git a/stubs/parsimonious/parsimonious/grammar.pyi b/stubs/parsimonious/parsimonious/grammar.pyi index ee6dde713..84855da64 100644 --- a/stubs/parsimonious/parsimonious/grammar.pyi +++ b/stubs/parsimonious/parsimonious/grammar.pyi @@ -23,7 +23,7 @@ class LazyReference(str): name: str def resolve_refs(self, rule_map: Mapping[str, Expression | LazyReference]) -> Expression: ... -class RuleVisitor(NodeVisitor): +class RuleVisitor(NodeVisitor[tuple[OrderedDict[str, Expression], Expression | None]]): quantifier_classes: dict[str, type[Expression]] visit_expression: Callable[[RuleVisitor, Node, collections.abc.Sequence[Any]], Any] visit_term: Callable[[RuleVisitor, Node, collections.abc.Sequence[Any]], Any] diff --git a/stubs/parsimonious/parsimonious/nodes.pyi b/stubs/parsimonious/parsimonious/nodes.pyi index 03aff4a5b..309a28cb1 100644 --- a/stubs/parsimonious/parsimonious/nodes.pyi +++ b/stubs/parsimonious/parsimonious/nodes.pyi @@ -1,7 +1,7 @@ from _typeshed import Incomplete from collections.abc import Callable, Iterator, Sequence from re import Match -from typing import Any, NoReturn, TypeVar +from typing import Any, Generic, TypeVar from parsimonious.exceptions import VisitationError as VisitationError from parsimonious.expressions import Expression @@ -27,14 +27,17 @@ class RegexNode(Node): class RuleDecoratorMeta(type): ... -class NodeVisitor(metaclass=RuleDecoratorMeta): +_VisitResultT = TypeVar("_VisitResultT") +_ChildT = TypeVar("_ChildT") + +class NodeVisitor(Generic[_VisitResultT], metaclass=RuleDecoratorMeta): grammar: Grammar | Incomplete unwrapped_exceptions: tuple[type[BaseException], ...] - def visit(self, node: Node) -> Any: ... - def generic_visit(self, node: Node, visited_children: Sequence[Any]) -> NoReturn: ... - def parse(self, text: str, pos: int = ...) -> Node: ... - def match(self, text: str, pos: int = ...) -> Node: ... - def lift_child(self, node: Node, children: Sequence[Any]) -> Any: ... + def visit(self, node: Node) -> _VisitResultT: ... + def generic_visit(self, node: Node, visited_children: Sequence[Any]) -> Incomplete: ... + def parse(self, text: str, pos: int = ...) -> _VisitResultT: ... + def match(self, text: str, pos: int = ...) -> _VisitResultT: ... + def lift_child(self, node: Node, children: Sequence[_ChildT]) -> _ChildT: ... _CallableT = TypeVar("_CallableT", bound=Callable[..., Any])