From 65c4ddfc57367a46c66e4f4d2a8f76e159c0a3a2 Mon Sep 17 00:00:00 2001 From: Kevin Kirsche Date: Tue, 13 Sep 2022 10:59:08 -0400 Subject: [PATCH] Update parsimonious to 0.10.0 (#8730) --- .../@tests/stubtest_allowlist.txt | 1 - stubs/parsimonious/METADATA.toml | 2 +- .../parsimonious/parsimonious/exceptions.pyi | 1 + .../parsimonious/parsimonious/expressions.pyi | 26 ++++++++++++------ stubs/parsimonious/parsimonious/grammar.pyi | 27 ++++++++++--------- stubs/parsimonious/parsimonious/nodes.pyi | 3 ++- 6 files changed, 36 insertions(+), 24 deletions(-) diff --git a/stubs/parsimonious/@tests/stubtest_allowlist.txt b/stubs/parsimonious/@tests/stubtest_allowlist.txt index ce8bec20df65..0da166241c76 100644 --- a/stubs/parsimonious/@tests/stubtest_allowlist.txt +++ b/stubs/parsimonious/@tests/stubtest_allowlist.txt @@ -1,2 +1 @@ -parsimonious.nodes.Node.__repr__ parsimonious.nodes.RuleDecoratorMeta.__new__ diff --git a/stubs/parsimonious/METADATA.toml b/stubs/parsimonious/METADATA.toml index 51e869b47983..5c7ed21e8ad5 100644 --- a/stubs/parsimonious/METADATA.toml +++ b/stubs/parsimonious/METADATA.toml @@ -1 +1 @@ -version = "0.9.*" +version = "0.10.*" diff --git a/stubs/parsimonious/parsimonious/exceptions.pyi b/stubs/parsimonious/parsimonious/exceptions.pyi index 243b0a4589a8..9401ce5f8d76 100644 --- a/stubs/parsimonious/parsimonious/exceptions.pyi +++ b/stubs/parsimonious/parsimonious/exceptions.pyi @@ -11,6 +11,7 @@ class ParseError(StrAndRepr, Exception): def line(self) -> int: ... def column(self) -> int: ... +class LeftRecursionError(ParseError): ... class IncompleteParseError(ParseError): ... class VisitationError(Exception): diff --git a/stubs/parsimonious/parsimonious/expressions.pyi b/stubs/parsimonious/parsimonious/expressions.pyi index a6dbc314bc96..fdc50b071c7d 100644 --- a/stubs/parsimonious/parsimonious/expressions.pyi +++ b/stubs/parsimonious/parsimonious/expressions.pyi @@ -1,4 +1,5 @@ import collections.abc +from _typeshed import Self from collections.abc import Callable, Mapping from re import Pattern from typing import Any, Union @@ -9,20 +10,22 @@ from parsimonious.grammar import Grammar from parsimonious.nodes import Node from parsimonious.utils import StrAndRepr -MARKER: Any - _CALLABLE_RETURN_TYPE: TypeAlias = Union[int, tuple[int, list[Node]], Node, None] _CALLABLE_TYPE: TypeAlias = ( Callable[[str, int], _CALLABLE_RETURN_TYPE] | Callable[[str, int, Mapping[tuple[int, int], Node], ParseError, Grammar], _CALLABLE_RETURN_TYPE] ) +def is_callable(value: object) -> bool: ... def expression(callable: _CALLABLE_TYPE, rule_name: str, grammar: Grammar) -> Expression: ... +IN_PROGRESS: object + class Expression(StrAndRepr): name: str identity_tuple: tuple[str] def __init__(self, name: str = ...) -> None: ... + def resolve_refs(self: Self, rule_map: Mapping[str, Expression]) -> Self: ... def parse(self, text: str, pos: int = ...) -> Node: ... def match(self, text: str, pos: int = ...) -> Node: ... def match_core(self, text: str, pos: int, cache: Mapping[tuple[int, int], Node], error: ParseError) -> Node: ... @@ -57,11 +60,18 @@ class Compound(Expression): class Sequence(Compound): ... class OneOf(Compound): ... -class Lookahead(Compound): ... -class Not(Compound): ... -class Optional(Compound): ... -class ZeroOrMore(Compound): ... -class OneOrMore(Compound): +class Lookahead(Compound): + negativity: bool + def __init__(self, member: Expression, *, negative: bool = ..., **kwargs: Any) -> None: ... + +def Not(term: Expression) -> Lookahead: ... + +class Quantifier(Compound): min: int - def __init__(self, member: Expression, name: str = ..., min: int = ...) -> None: ... + max: float + def __init__(self, member: Expression, *, min: int = ..., max: float = ..., name: str = ..., **kwargs: Any) -> None: ... + +def ZeroOrMore(member: Expression, name: str = ...) -> Quantifier: ... +def OneOrMore(member: Expression, name: str = ..., min: int = ...) -> Quantifier: ... +def Optional(member: Expression, name: str = ...) -> Quantifier: ... diff --git a/stubs/parsimonious/parsimonious/grammar.pyi b/stubs/parsimonious/parsimonious/grammar.pyi index a302df492135..f686df326c65 100644 --- a/stubs/parsimonious/parsimonious/grammar.pyi +++ b/stubs/parsimonious/parsimonious/grammar.pyi @@ -3,7 +3,7 @@ from collections import OrderedDict from collections.abc import Callable, Mapping from typing import Any, NoReturn -from parsimonious.expressions import _CALLABLE_TYPE, Expression, Literal, Lookahead, Not, OneOf, Regex, Sequence, TokenMatcher +from parsimonious.expressions import _CALLABLE_TYPE, Expression, Literal, Lookahead, OneOf, Regex, Sequence, TokenMatcher from parsimonious.nodes import Node, NodeVisitor class Grammar(OrderedDict[str, Expression]): @@ -20,6 +20,7 @@ rule_syntax: str class LazyReference(str): name: str + def resolve_refs(self, rule_map: Mapping[str, Expression | LazyReference]) -> Expression: ... class RuleVisitor(NodeVisitor): quantifier_classes: dict[str, type[Expression]] @@ -28,24 +29,24 @@ class RuleVisitor(NodeVisitor): visit_atom: Callable[[RuleVisitor, Node, collections.abc.Sequence[Any]], Any] custom_rules: dict[str, Expression] def __init__(self, custom_rules: Mapping[str, Expression] | None = ...) -> None: ... - def visit_rules( - self, node: Node, rules_list: collections.abc.Sequence[Any] - ) -> tuple[OrderedDict[str, Expression], Expression | None]: ... + def visit_parenthesized(self, node: Node, parenthesized: collections.abc.Sequence[Any]) -> Expression: ... + def visit_quantifier(self, node: Node, quantifier: collections.abc.Sequence[Any]) -> Node: ... + def visit_quantified(self, node: Node, quantified: collections.abc.Sequence[Any]) -> Expression: ... + def visit_lookahead_term(self, node: Node, lookahead_term: collections.abc.Sequence[Any]) -> Lookahead: ... + def visit_not_term(self, node: Node, not_term: collections.abc.Sequence[Any]) -> Lookahead: ... def visit_rule(self, node: Node, rule: collections.abc.Sequence[Any]) -> Expression: ... - def visit_label(self, node: Node, label: collections.abc.Sequence[Any]) -> str: ... + def visit_sequence(self, node: Node, sequence: collections.abc.Sequence[Any]) -> Sequence: ... def visit_ored(self, node: Node, ored: collections.abc.Sequence[Any]) -> OneOf: ... def visit_or_term(self, node: Node, or_term: collections.abc.Sequence[Any]) -> Expression: ... - def visit_sequence(self, node: Node, sequence: collections.abc.Sequence[Any]) -> Sequence: ... - def visit_not_term(self, node: Node, not_term: collections.abc.Sequence[Any]) -> Not: ... - def visit_lookahead_term(self, node: Node, lookahead_term: collections.abc.Sequence[Any]) -> Lookahead: ... - def visit_quantified(self, node: Node, quantified: collections.abc.Sequence[Any]) -> Expression: ... - def visit_quantifier(self, node: Node, quantifier: collections.abc.Sequence[Any]) -> Node: ... + def visit_label(self, node: Node, label: collections.abc.Sequence[Any]) -> str: ... def visit_reference(self, node: Node, reference: collections.abc.Sequence[Any]) -> LazyReference: ... - def visit_literal(self, node: Node, literal: collections.abc.Sequence[Any]) -> Literal: ... - def visit_spaceless_literal(self, spaceless_literal: Node, visited_children: collections.abc.Sequence[Any]) -> Literal: ... def visit_regex(self, node: Node, regex: collections.abc.Sequence[Any]) -> Regex: ... - def visit_parenthesized(self, node: Node, parenthesized: collections.abc.Sequence[Any]) -> Expression: ... + def visit_spaceless_literal(self, spaceless_literal: Node, visited_children: collections.abc.Sequence[Any]) -> Literal: ... + def visit_literal(self, node: Node, literal: collections.abc.Sequence[Any]) -> Literal: ... def generic_visit(self, node: Node, visited_children: collections.abc.Sequence[Any]) -> collections.abc.Sequence[Any] | Node: ... # type: ignore[override] + def visit_rules( + self, node: Node, rules_list: collections.abc.Sequence[Any] + ) -> tuple[OrderedDict[str, Expression], Expression | None]: ... class TokenRuleVisitor(RuleVisitor): def visit_spaceless_literal( diff --git a/stubs/parsimonious/parsimonious/nodes.pyi b/stubs/parsimonious/parsimonious/nodes.pyi index 15cfb6b64b4b..cffd15569870 100644 --- a/stubs/parsimonious/parsimonious/nodes.pyi +++ b/stubs/parsimonious/parsimonious/nodes.pyi @@ -19,6 +19,7 @@ class Node: @property def text(self) -> str: ... def prettily(self, error: Node | None = ...) -> str: ... + def __repr__(self, top_level: bool = ...) -> str: ... class RegexNode(Node): match: Match[str] @@ -27,7 +28,7 @@ class RuleDecoratorMeta(type): ... class NodeVisitor(metaclass=RuleDecoratorMeta): grammar: Grammar | Any - unwrapped_exceptions: tuple[type[Exception], ...] + 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: ...