Skip to content

Improve stubs for commonmark #13681

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
180 changes: 92 additions & 88 deletions stubs/commonmark/commonmark/blocks.pyi
Original file line number Diff line number Diff line change
@@ -1,141 +1,144 @@
from _typeshed import Incomplete
from typing import Any

CODE_INDENT: int
reHtmlBlockOpen: Any
reHtmlBlockClose: Any
reThematicBreak: Any
reMaybeSpecial: Any
reNonSpace: Any
reBulletListMarker: Any
reOrderedListMarker: Any
reATXHeadingMarker: Any
reCodeFence: Any
reClosingCodeFence: Any
reSetextHeadingLine: Any
reLineEnding: Any

def is_blank(s): ...
def is_space_or_tab(s): ...
def peek(ln, pos): ...
def ends_with_blank_line(block): ...
def parse_list_marker(parser, container): ...
def lists_match(list_data, item_data): ...
import re
from typing import Any, Final, Literal

from .inlines import InlineParser
from .node import Node

CODE_INDENT: Final[int]
reHtmlBlockOpen: Final[list[re.Pattern[str]]]
reHtmlBlockClose: Final[list[re.Pattern[str]]]
reThematicBreak: Final[re.Pattern[str]]
reMaybeSpecial: Final[re.Pattern[str]]
reNonSpace: Final[re.Pattern[str]]
reBulletListMarker: Final[re.Pattern[str]]
reOrderedListMarker: Final[re.Pattern[str]]
reATXHeadingMarker: Final[re.Pattern[str]]
reCodeFence: Final[re.Pattern[str]]
reClosingCodeFence: Final[re.Pattern[str]]
reSetextHeadingLine: Final[re.Pattern[str]]
reLineEnding: Final[re.Pattern[str]]

def is_blank(s: str) -> bool: ...
def is_space_or_tab(s: str) -> bool: ...
def peek(ln: str, pos: int) -> str | None: ...
def ends_with_blank_line(block: Node) -> bool: ...
def parse_list_marker(parser: Parser, container: Node) -> dict[str, Any] | None: ...
def lists_match(list_data: dict[str, Any], item_data: dict[str, Any]) -> bool: ...

class Block:
accepts_lines: Any
accepts_lines: bool | None
@staticmethod
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...) -> None: ...
def continue_(parser: Parser | None = None, container: Node | None = None) -> int | None: ...
@staticmethod
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
@staticmethod
def can_contain(t) -> None: ...
def can_contain(t: str) -> bool | None: ...

class Document(Block):
accepts_lines: bool
accepts_lines: Literal[False]
@staticmethod
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0]: ...
@staticmethod
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
@staticmethod
def can_contain(t): ...
def can_contain(t: str) -> bool: ...

class List(Block):
accepts_lines: bool
accepts_lines: Literal[False]
@staticmethod
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0]: ...
@staticmethod
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
@staticmethod
def can_contain(t): ...
def can_contain(t: str) -> bool: ...

class BlockQuote(Block):
accepts_lines: bool
accepts_lines: Literal[False]
@staticmethod
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0, 1]: ...
@staticmethod
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
@staticmethod
def can_contain(t): ...
def can_contain(t: str) -> bool: ...

class Item(Block):
accepts_lines: bool
accepts_lines: Literal[False]
@staticmethod
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0, 1]: ...
@staticmethod
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
@staticmethod
def can_contain(t): ...
def can_contain(t: str) -> bool: ...

class Heading(Block):
accepts_lines: bool
accepts_lines: Literal[False]
@staticmethod
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[1]: ...
@staticmethod
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
@staticmethod
def can_contain(t): ...
def can_contain(t: str) -> Literal[False]: ...

class ThematicBreak(Block):
accepts_lines: bool
accepts_lines: Literal[False]
@staticmethod
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[1]: ...
@staticmethod
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
@staticmethod
def can_contain(t): ...
def can_contain(t: str) -> Literal[False]: ...

class CodeBlock(Block):
accepts_lines: bool
accepts_lines: Literal[True]
@staticmethod
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0, 1, 2]: ...
@staticmethod
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
@staticmethod
def can_contain(t): ...
def can_contain(t: str) -> Literal[False]: ...

class HtmlBlock(Block):
accepts_lines: bool
accepts_lines: Literal[True]
@staticmethod
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0, 1]: ...
@staticmethod
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
@staticmethod
def can_contain(t): ...
def can_contain(t: str) -> Literal[False]: ...

class Paragraph(Block):
accepts_lines: bool
accepts_lines: Literal[True]
@staticmethod
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0, 1]: ...
@staticmethod
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
@staticmethod
def can_contain(t): ...
def can_contain(t: str) -> Literal[False]: ...

class BlockStarts:
METHODS: Any
METHODS: list[str]
@staticmethod
def block_quote(parser, container: Incomplete | None = ...): ...
def block_quote(parser: Parser, container: Node | None = None) -> Literal[0, 1]: ...
@staticmethod
def atx_heading(parser, container: Incomplete | None = ...): ...
def atx_heading(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...
@staticmethod
def fenced_code_block(parser, container: Incomplete | None = ...): ...
def fenced_code_block(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...
@staticmethod
def html_block(parser, container: Incomplete | None = ...): ...
def html_block(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...
@staticmethod
def setext_heading(parser, container: Incomplete | None = ...): ...
def setext_heading(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...
@staticmethod
def thematic_break(parser, container: Incomplete | None = ...): ...
def thematic_break(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...
@staticmethod
def list_item(parser, container: Incomplete | None = ...): ...
def list_item(parser: Parser, container: Node | None = None) -> Literal[0, 1]: ...
@staticmethod
def indented_code_block(parser, container: Incomplete | None = ...): ...
def indented_code_block(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...

class Parser:
doc: Any
block_starts: Any
tip: Any
oldtip: Any
doc: Node
block_starts: BlockStarts
tip: Node
oldtip: Node
current_line: str
line_number: int
offset: int
Expand All @@ -147,21 +150,22 @@ class Parser:
blank: bool
partially_consumed_tab: bool
all_closed: bool
last_matched_container: Any
refmap: Any
last_matched_container: Node
refmap: dict[str, Any]
last_line_length: int
inline_parser: Any
options: Any
def __init__(self, options=...) -> None: ...
inline_parser: InlineParser
options: dict[str, Any]
blocks: dict[str, Block]
def __init__(self, options: dict[str, Any] = {}) -> None: ...
def add_line(self) -> None: ...
def add_child(self, tag, offset): ...
def add_child(self, tag: str, offset: int) -> Node: ...
def close_unmatched_blocks(self) -> None: ...
def find_next_nonspace(self) -> None: ...
def advance_next_nonspace(self) -> None: ...
def advance_offset(self, count, columns) -> None: ...
def incorporate_line(self, ln) -> None: ...
def finalize(self, block, line_number) -> None: ...
def process_inlines(self, block) -> None: ...
def parse(self, my_input): ...
def advance_offset(self, count: int, columns: bool) -> None: ...
def incorporate_line(self, ln: str) -> None: ...
def finalize(self, block: Node, line_number: int) -> None: ...
def process_inlines(self, block: Node) -> None: ...
def parse(self, my_input: str) -> Node: ...

CAMEL_RE: Any
CAMEL_RE: Final[re.Pattern[str]]
62 changes: 33 additions & 29 deletions stubs/commonmark/commonmark/common.pyi
Original file line number Diff line number Diff line change
@@ -1,35 +1,39 @@
import html
from typing import Any
import re
from typing import AnyStr, Final, Literal, overload

HTMLunescape = html.unescape
ENTITY: str
TAGNAME: str
ATTRIBUTENAME: str
UNQUOTEDVALUE: str
SINGLEQUOTEDVALUE: str
DOUBLEQUOTEDVALUE: str
ATTRIBUTEVALUE: Any
ATTRIBUTEVALUESPEC: Any
ATTRIBUTE: Any
OPENTAG: Any
CLOSETAG: Any
HTMLCOMMENT: str
PROCESSINGINSTRUCTION: str
DECLARATION: Any
CDATA: str
HTMLTAG: Any
reHtmlTag: Any
reBackslashOrAmp: Any
ESCAPABLE: str
reEntityOrEscapedChar: Any
XMLSPECIAL: str
reXmlSpecial: Any
ENTITY: Final[str]
TAGNAME: Final[str]
ATTRIBUTENAME: Final[str]
UNQUOTEDVALUE: Final[str]
SINGLEQUOTEDVALUE: Final[str]
DOUBLEQUOTEDVALUE: Final[str]
ATTRIBUTEVALUE: Final[str]
ATTRIBUTEVALUESPEC: Final[str]
ATTRIBUTE: Final[str]
OPENTAG: Final[str]
CLOSETAG: Final[str]
HTMLCOMMENT: Final[str]
PROCESSINGINSTRUCTION: Final[str]
DECLARATION: Final[str]
CDATA: Final[str]
HTMLTAG: Final[str]
reHtmlTag: Final[re.Pattern[str]]
reBackslashOrAmp: Final[re.Pattern[str]]
ESCAPABLE: Final[str]
reEntityOrEscapedChar: Final[re.Pattern[str]]
XMLSPECIAL: Final[str]
reXmlSpecial: Final[re.Pattern[str]]

def unescape_char(s): ...
def unescape_string(s): ...
def normalize_uri(uri): ...
def unescape_char(s: AnyStr) -> AnyStr: ...
def unescape_string(s: str) -> str: ...
def normalize_uri(uri: str) -> str: ...

UNSAFE_MAP: Any
UNSAFE_MAP: Final[dict[str, str]]

def replace_unsafe_char(s): ...
def escape_xml(s): ...
def replace_unsafe_char(s: str) -> str: ...
@overload
def escape_xml(s: None) -> Literal[""]: ...
@overload
def escape_xml(s: str) -> str: ...
10 changes: 7 additions & 3 deletions stubs/commonmark/commonmark/dump.pyi
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
def prepare(obj, topnode: bool = ...): ...
def dumpJSON(obj): ...
def dumpAST(obj, ind: int = ..., topnode: bool = ...) -> None: ...
from typing import Any

from .node import Node

def prepare(obj: Node, topnode: bool = ...) -> list[dict[str, Any]]: ...
def dumpJSON(obj: Node) -> str: ...
def dumpAST(obj: Node, ind: int = ..., topnode: bool = ...) -> None: ...
Loading