Skip to content

Commit 8ff3278

Browse files
author
Oleh Mazur
authored
parsimonious: Update return types of NodeVisitor's methods (#9564)
1 parent f8add36 commit 8ff3278

File tree

2 files changed

+11
-8
lines changed

2 files changed

+11
-8
lines changed

stubs/parsimonious/parsimonious/grammar.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class LazyReference(str):
2323
name: str
2424
def resolve_refs(self, rule_map: Mapping[str, Expression | LazyReference]) -> Expression: ...
2525

26-
class RuleVisitor(NodeVisitor):
26+
class RuleVisitor(NodeVisitor[tuple[OrderedDict[str, Expression], Expression | None]]):
2727
quantifier_classes: dict[str, type[Expression]]
2828
visit_expression: Callable[[RuleVisitor, Node, collections.abc.Sequence[Any]], Any]
2929
visit_term: Callable[[RuleVisitor, Node, collections.abc.Sequence[Any]], Any]

stubs/parsimonious/parsimonious/nodes.pyi

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from _typeshed import Incomplete
22
from collections.abc import Callable, Iterator, Sequence
33
from re import Match
4-
from typing import Any, NoReturn, TypeVar
4+
from typing import Any, Generic, TypeVar
55

66
from parsimonious.exceptions import VisitationError as VisitationError
77
from parsimonious.expressions import Expression
@@ -27,14 +27,17 @@ class RegexNode(Node):
2727

2828
class RuleDecoratorMeta(type): ...
2929

30-
class NodeVisitor(metaclass=RuleDecoratorMeta):
30+
_VisitResultT = TypeVar("_VisitResultT")
31+
_ChildT = TypeVar("_ChildT")
32+
33+
class NodeVisitor(Generic[_VisitResultT], metaclass=RuleDecoratorMeta):
3134
grammar: Grammar | Incomplete
3235
unwrapped_exceptions: tuple[type[BaseException], ...]
33-
def visit(self, node: Node) -> Any: ...
34-
def generic_visit(self, node: Node, visited_children: Sequence[Any]) -> NoReturn: ...
35-
def parse(self, text: str, pos: int = ...) -> Node: ...
36-
def match(self, text: str, pos: int = ...) -> Node: ...
37-
def lift_child(self, node: Node, children: Sequence[Any]) -> Any: ...
36+
def visit(self, node: Node) -> _VisitResultT: ...
37+
def generic_visit(self, node: Node, visited_children: Sequence[Any]) -> Incomplete: ...
38+
def parse(self, text: str, pos: int = ...) -> _VisitResultT: ...
39+
def match(self, text: str, pos: int = ...) -> _VisitResultT: ...
40+
def lift_child(self, node: Node, children: Sequence[_ChildT]) -> _ChildT: ...
3841

3942
_CallableT = TypeVar("_CallableT", bound=Callable[..., Any])
4043

0 commit comments

Comments
 (0)