Skip to content

Commit

Permalink
improve type annotations in 'docutils.parsers.rst.states.Inliner' (py…
Browse files Browse the repository at this point in the history
  • Loading branch information
danieleades authored Mar 3, 2024
1 parent 23daf97 commit 1c40e64
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 6 deletions.
11 changes: 5 additions & 6 deletions stubs/docutils/@tests/stubtest_allowlist.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
docutils.TransformSpec.unknown_reference_resolvers
docutils.frontend.ConfigParser.__getattr__
docutils.frontend.ConfigParser.read
docutils.frontend.OptionParser.__getattr__
Expand All @@ -7,16 +6,16 @@ docutils.io.FileOutput.__init__
docutils.io.Input.__init__
docutils.languages.LanguageImporter.__getattr__
docutils.nodes.Element.__getattr__
docutils.nodes.GenericNodeVisitor.__getattr__
docutils.nodes.Element.__iter__ # doesn't exist at runtime, but the class is iterable due to __getitem__
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__
docutils.parsers.recommonmark_wrapper

# the constructor appears to be mostly internal API, public API users are meant to use docutils.utils.new_reporter instead
docutils.utils.Reporter.__init__

# 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__
91 changes: 91 additions & 0 deletions stubs/docutils/docutils/parsers/rst/states.pyi
Original file line number Diff line number Diff line change
@@ -1,6 +1,97 @@
from _typeshed import Incomplete
from collections.abc import Callable, Sequence
from re import Match, Pattern
from types import ModuleType
from typing import Any
from typing_extensions import TypeAlias

from docutils import nodes
from docutils.utils import Reporter

class Struct:
def __init__(self, **keywordargs) -> None: ...

_BasicDefinition: TypeAlias = tuple[str, str, str, list[Pattern[str]]]
_DefinitionParts: TypeAlias = tuple[str, str, str, list[Pattern[str] | _BasicDefinition]]
_DefinitionType: TypeAlias = tuple[str, str, str, list[Pattern[str] | _DefinitionParts]]

class Inliner:
implicit_dispatch: list[tuple[Pattern[str], Callable[[Match[str], int], Sequence[nodes.Node]]]]
def __init__(self) -> None: ...
start_string_prefix: str
end_string_suffix: str
parts: _DefinitionType
patterns: Any
def init_customizations(self, settings: Any) -> None: ...
reporter: Reporter
document: nodes.document
language: ModuleType
parent: nodes.Element
def parse(
self, text: str, lineno: int, memo: Struct, parent: nodes.Element
) -> tuple[list[nodes.Node], list[nodes.system_message]]: ...
non_whitespace_before: str
non_whitespace_escape_before: str
non_unescaped_whitespace_escape_before: str
non_whitespace_after: str
simplename: str
uric: str
uri_end_delim: str
urilast: str
uri_end: str
emailc: str
email_pattern: str
def quoted_start(self, match: Match[str]) -> bool: ...
def inline_obj(
self,
match: Match[str],
lineno: int,
end_pattern: Pattern[str],
nodeclass: nodes.TextElement,
restore_backslashes: bool = False,
) -> tuple[str, list[nodes.problematic], str, list[nodes.system_message], str]: ...
def problematic(self, text: str, rawsource: str, message: nodes.system_message) -> nodes.problematic: ...
def emphasis(
self, match: Match[str], lineno: int
) -> tuple[str, list[nodes.problematic], str, list[nodes.system_message]]: ...
def strong(self, match: Match[str], lineno: int) -> tuple[str, list[nodes.problematic], str, list[nodes.system_message]]: ...
def interpreted_or_phrase_ref(
self, match: Match[str], lineno: int
) -> tuple[str, list[nodes.problematic], str, list[nodes.system_message]]: ...
def phrase_ref(
self, before: str, after: str, rawsource: str, escaped: str, text: str | None = None
) -> tuple[str, list[nodes.Node], str, list[nodes.Node]]: ...
def adjust_uri(self, uri: str) -> str: ...
def interpreted(
self, rawsource: str, text: str, role: str, lineno: int
) -> tuple[list[nodes.Node], list[nodes.system_message]]: ...
def literal(self, match: Match[str], lineno: int) -> tuple[str, list[nodes.problematic], str, list[nodes.system_message]]: ...
def inline_internal_target(
self, match: Match[str], lineno: int
) -> tuple[str, list[nodes.problematic], str, list[nodes.system_message]]: ...
def substitution_reference(
self, match: Match[str], lineno: int
) -> tuple[str, list[nodes.problematic], str, list[nodes.system_message]]: ...
def footnote_reference(
self, match: Match[str], lineno: int
) -> tuple[str, list[nodes.problematic], str, list[nodes.system_message]]: ...
def reference(
self, match: Match[str], lineno: int, anonymous: bool = ...
) -> tuple[str, list[nodes.problematic], str, list[nodes.system_message]]: ...
def anonymous_reference(
self, match: Match[str], lineno: int
) -> tuple[str, list[nodes.problematic], str, list[nodes.system_message]]: ...
def standalone_uri(
self, match: Match[str], lineno: int
) -> list[tuple[str, list[nodes.problematic], str, list[nodes.system_message]]]: ...
def pep_reference(
self, match: Match[str], lineno: int
) -> list[tuple[str, list[nodes.problematic], str, list[nodes.system_message]]]: ...
rfc_url: str = ...
def rfc_reference(
self, match: Match[str], lineno: int
) -> list[tuple[str, list[nodes.problematic], str, list[nodes.system_message]]]: ...
def implicit_inline(self, text: str, lineno: int) -> list[nodes.Text]: ...
dispatch: dict[str, Callable[[Match[str], int], tuple[str, list[nodes.problematic], str, list[nodes.system_message]]]] = ...

def __getattr__(name: str) -> Incomplete: ...

0 comments on commit 1c40e64

Please sign in to comment.