Skip to content

Commit

Permalink
Improve type annotations in 'docutils.parsers.rst' (#11523)
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades authored Mar 8, 2024
1 parent 52daae5 commit 3646f64
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 15 deletions.
2 changes: 0 additions & 2 deletions stubs/docutils/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@ docutils.nodes.GenericNodeVisitor.__getattr__
# these methods take a rawsource parameter that has been deprecated and is completely ignored, so we omit it from the stub
docutils.nodes.Text.__new__
docutils.parsers.recommonmark_wrapper
docutils.parsers.rst.Directive.__getattr__
docutils.transforms.Transform.__getattr__
docutils.transforms.Transformer.__getattr__
docutils.TransformSpec.unknown_reference_resolvers
docutils.utils.Reporter.__getattr__

# the constructor appears to be mostly internal API, public API users are meant to use docutils.utils.new_reporter instead
docutils.utils.Reporter.__init__
59 changes: 46 additions & 13 deletions stubs/docutils/docutils/parsers/rst/__init__.pyi
Original file line number Diff line number Diff line change
@@ -1,34 +1,67 @@
from _typeshed import Incomplete
from collections.abc import Callable, Sequence
from typing import Any, ClassVar, Literal
from typing_extensions import TypeAlias

from docutils import parsers
from docutils.parsers.rst import states
from docutils import nodes, parsers
from docutils.parsers.rst.states import Inliner, RSTState, RSTStateMachine
from docutils.statemachine import StringList
from docutils.transforms import Transform

class Parser(parsers.Parser):
settings_spec: ClassVar[Incomplete]
config_section_dependencies: ClassVar[tuple[str, ...]]
initial_state: Literal["Body", "RFC2822Body"]
state_classes: Any
inliner: Any
def __init__(self, rfc2822: bool = False, inliner: Incomplete | None = None) -> None: ...
state_classes: Sequence[type[RSTState]]
inliner: Inliner | None
def __init__(self, rfc2822: bool = False, inliner: Inliner | None = None) -> None: ...
def get_transforms(self) -> list[type[Transform]]: ...
def parse(self, inputstring: str, document: nodes.document) -> None: ...

class DirectiveError(Exception):
level: Any
level: int
msg: str
def __init__(self, level: Any, message: str) -> None: ...
def __init__(self, level: int, message: str) -> None: ...

class Directive:
required_arguments: int
optional_arguments: int
final_argument_whitespace: bool
option_spec: dict[str, Callable[[str], Any]] | None
has_content: bool
name: str
arguments: list[str]
options: dict[str, Any]
content: StringList
lineno: int
content_offset: int
block_text: str
state: RSTState
state_machine: RSTStateMachine = ...
def __init__(
self,
name: str,
arguments: list[Any],
arguments: list[str],
options: dict[str, Any],
content: list[str],
content: StringList,
lineno: int,
content_offset: int,
block_text: str,
state: states.RSTState,
state_machine: states.RSTStateMachine,
state: RSTState,
state_machine: RSTStateMachine,
) -> None: ...
def __getattr__(self, name: str) -> Incomplete: ...
def run(self) -> Sequence[nodes.Node]: ...
def directive_error(self, level: int, message: str) -> DirectiveError: ...
def debug(self, message: str) -> DirectiveError: ...
def info(self, message: str) -> DirectiveError: ...
def warning(self, message: str) -> DirectiveError: ...
def error(self, message: str) -> DirectiveError: ...
def severe(self, message: str) -> DirectiveError: ...
def assert_has_content(self) -> None: ...
def add_name(self, node: nodes.Node) -> None: ...

def convert_directive_function(directive_fn): ...
_DirectiveFn: TypeAlias = Callable[
[str, list[str], dict[str, Any], StringList, int, int, str, RSTState, RSTStateMachine], Directive
]

def convert_directive_function(directive_fn: _DirectiveFn) -> type[Directive]: ...

0 comments on commit 3646f64

Please sign in to comment.