Skip to content

Commit cb2beae

Browse files
authored
Improve stubs for commonmark (#13681)
1 parent fd62d20 commit cb2beae

File tree

10 files changed

+287
-264
lines changed

10 files changed

+287
-264
lines changed
Lines changed: 92 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,141 +1,144 @@
1-
from _typeshed import Incomplete
2-
from typing import Any
3-
4-
CODE_INDENT: int
5-
reHtmlBlockOpen: Any
6-
reHtmlBlockClose: Any
7-
reThematicBreak: Any
8-
reMaybeSpecial: Any
9-
reNonSpace: Any
10-
reBulletListMarker: Any
11-
reOrderedListMarker: Any
12-
reATXHeadingMarker: Any
13-
reCodeFence: Any
14-
reClosingCodeFence: Any
15-
reSetextHeadingLine: Any
16-
reLineEnding: Any
17-
18-
def is_blank(s): ...
19-
def is_space_or_tab(s): ...
20-
def peek(ln, pos): ...
21-
def ends_with_blank_line(block): ...
22-
def parse_list_marker(parser, container): ...
23-
def lists_match(list_data, item_data): ...
1+
import re
2+
from typing import Any, Final, Literal
3+
4+
from .inlines import InlineParser
5+
from .node import Node
6+
7+
CODE_INDENT: Final[int]
8+
reHtmlBlockOpen: Final[list[re.Pattern[str]]]
9+
reHtmlBlockClose: Final[list[re.Pattern[str]]]
10+
reThematicBreak: Final[re.Pattern[str]]
11+
reMaybeSpecial: Final[re.Pattern[str]]
12+
reNonSpace: Final[re.Pattern[str]]
13+
reBulletListMarker: Final[re.Pattern[str]]
14+
reOrderedListMarker: Final[re.Pattern[str]]
15+
reATXHeadingMarker: Final[re.Pattern[str]]
16+
reCodeFence: Final[re.Pattern[str]]
17+
reClosingCodeFence: Final[re.Pattern[str]]
18+
reSetextHeadingLine: Final[re.Pattern[str]]
19+
reLineEnding: Final[re.Pattern[str]]
20+
21+
def is_blank(s: str) -> bool: ...
22+
def is_space_or_tab(s: str) -> bool: ...
23+
def peek(ln: str, pos: int) -> str | None: ...
24+
def ends_with_blank_line(block: Node) -> bool: ...
25+
def parse_list_marker(parser: Parser, container: Node) -> dict[str, Any] | None: ...
26+
def lists_match(list_data: dict[str, Any], item_data: dict[str, Any]) -> bool: ...
2427

2528
class Block:
26-
accepts_lines: Any
29+
accepts_lines: bool | None
2730
@staticmethod
28-
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...) -> None: ...
31+
def continue_(parser: Parser | None = None, container: Node | None = None) -> int | None: ...
2932
@staticmethod
30-
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
33+
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
3134
@staticmethod
32-
def can_contain(t) -> None: ...
35+
def can_contain(t: str) -> bool | None: ...
3336

3437
class Document(Block):
35-
accepts_lines: bool
38+
accepts_lines: Literal[False]
3639
@staticmethod
37-
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
40+
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0]: ...
3841
@staticmethod
39-
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
42+
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
4043
@staticmethod
41-
def can_contain(t): ...
44+
def can_contain(t: str) -> bool: ...
4245

4346
class List(Block):
44-
accepts_lines: bool
47+
accepts_lines: Literal[False]
4548
@staticmethod
46-
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
49+
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0]: ...
4750
@staticmethod
48-
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
51+
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
4952
@staticmethod
50-
def can_contain(t): ...
53+
def can_contain(t: str) -> bool: ...
5154

5255
class BlockQuote(Block):
53-
accepts_lines: bool
56+
accepts_lines: Literal[False]
5457
@staticmethod
55-
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
58+
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0, 1]: ...
5659
@staticmethod
57-
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
60+
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
5861
@staticmethod
59-
def can_contain(t): ...
62+
def can_contain(t: str) -> bool: ...
6063

6164
class Item(Block):
62-
accepts_lines: bool
65+
accepts_lines: Literal[False]
6366
@staticmethod
64-
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
67+
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0, 1]: ...
6568
@staticmethod
66-
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
69+
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
6770
@staticmethod
68-
def can_contain(t): ...
71+
def can_contain(t: str) -> bool: ...
6972

7073
class Heading(Block):
71-
accepts_lines: bool
74+
accepts_lines: Literal[False]
7275
@staticmethod
73-
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
76+
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[1]: ...
7477
@staticmethod
75-
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
78+
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
7679
@staticmethod
77-
def can_contain(t): ...
80+
def can_contain(t: str) -> Literal[False]: ...
7881

7982
class ThematicBreak(Block):
80-
accepts_lines: bool
83+
accepts_lines: Literal[False]
8184
@staticmethod
82-
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
85+
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[1]: ...
8386
@staticmethod
84-
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
87+
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
8588
@staticmethod
86-
def can_contain(t): ...
89+
def can_contain(t: str) -> Literal[False]: ...
8790

8891
class CodeBlock(Block):
89-
accepts_lines: bool
92+
accepts_lines: Literal[True]
9093
@staticmethod
91-
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
94+
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0, 1, 2]: ...
9295
@staticmethod
93-
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
96+
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
9497
@staticmethod
95-
def can_contain(t): ...
98+
def can_contain(t: str) -> Literal[False]: ...
9699

97100
class HtmlBlock(Block):
98-
accepts_lines: bool
101+
accepts_lines: Literal[True]
99102
@staticmethod
100-
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
103+
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0, 1]: ...
101104
@staticmethod
102-
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
105+
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
103106
@staticmethod
104-
def can_contain(t): ...
107+
def can_contain(t: str) -> Literal[False]: ...
105108

106109
class Paragraph(Block):
107-
accepts_lines: bool
110+
accepts_lines: Literal[True]
108111
@staticmethod
109-
def continue_(parser: Incomplete | None = ..., container: Incomplete | None = ...): ...
112+
def continue_(parser: Parser | None = None, container: Node | None = None) -> Literal[0, 1]: ...
110113
@staticmethod
111-
def finalize(parser: Incomplete | None = ..., block: Incomplete | None = ...) -> None: ...
114+
def finalize(parser: Parser | None = None, block: Node | None = None) -> None: ...
112115
@staticmethod
113-
def can_contain(t): ...
116+
def can_contain(t: str) -> Literal[False]: ...
114117

115118
class BlockStarts:
116-
METHODS: Any
119+
METHODS: list[str]
117120
@staticmethod
118-
def block_quote(parser, container: Incomplete | None = ...): ...
121+
def block_quote(parser: Parser, container: Node | None = None) -> Literal[0, 1]: ...
119122
@staticmethod
120-
def atx_heading(parser, container: Incomplete | None = ...): ...
123+
def atx_heading(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...
121124
@staticmethod
122-
def fenced_code_block(parser, container: Incomplete | None = ...): ...
125+
def fenced_code_block(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...
123126
@staticmethod
124-
def html_block(parser, container: Incomplete | None = ...): ...
127+
def html_block(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...
125128
@staticmethod
126-
def setext_heading(parser, container: Incomplete | None = ...): ...
129+
def setext_heading(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...
127130
@staticmethod
128-
def thematic_break(parser, container: Incomplete | None = ...): ...
131+
def thematic_break(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...
129132
@staticmethod
130-
def list_item(parser, container: Incomplete | None = ...): ...
133+
def list_item(parser: Parser, container: Node | None = None) -> Literal[0, 1]: ...
131134
@staticmethod
132-
def indented_code_block(parser, container: Incomplete | None = ...): ...
135+
def indented_code_block(parser: Parser, container: Node | None = None) -> Literal[0, 2]: ...
133136

134137
class Parser:
135-
doc: Any
136-
block_starts: Any
137-
tip: Any
138-
oldtip: Any
138+
doc: Node
139+
block_starts: BlockStarts
140+
tip: Node
141+
oldtip: Node
139142
current_line: str
140143
line_number: int
141144
offset: int
@@ -147,21 +150,22 @@ class Parser:
147150
blank: bool
148151
partially_consumed_tab: bool
149152
all_closed: bool
150-
last_matched_container: Any
151-
refmap: Any
153+
last_matched_container: Node
154+
refmap: dict[str, Any]
152155
last_line_length: int
153-
inline_parser: Any
154-
options: Any
155-
def __init__(self, options=...) -> None: ...
156+
inline_parser: InlineParser
157+
options: dict[str, Any]
158+
blocks: dict[str, Block]
159+
def __init__(self, options: dict[str, Any] = {}) -> None: ...
156160
def add_line(self) -> None: ...
157-
def add_child(self, tag, offset): ...
161+
def add_child(self, tag: str, offset: int) -> Node: ...
158162
def close_unmatched_blocks(self) -> None: ...
159163
def find_next_nonspace(self) -> None: ...
160164
def advance_next_nonspace(self) -> None: ...
161-
def advance_offset(self, count, columns) -> None: ...
162-
def incorporate_line(self, ln) -> None: ...
163-
def finalize(self, block, line_number) -> None: ...
164-
def process_inlines(self, block) -> None: ...
165-
def parse(self, my_input): ...
165+
def advance_offset(self, count: int, columns: bool) -> None: ...
166+
def incorporate_line(self, ln: str) -> None: ...
167+
def finalize(self, block: Node, line_number: int) -> None: ...
168+
def process_inlines(self, block: Node) -> None: ...
169+
def parse(self, my_input: str) -> Node: ...
166170

167-
CAMEL_RE: Any
171+
CAMEL_RE: Final[re.Pattern[str]]
Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,39 @@
11
import html
2-
from typing import Any
2+
import re
3+
from typing import AnyStr, Final, Literal, overload
34

45
HTMLunescape = html.unescape
5-
ENTITY: str
6-
TAGNAME: str
7-
ATTRIBUTENAME: str
8-
UNQUOTEDVALUE: str
9-
SINGLEQUOTEDVALUE: str
10-
DOUBLEQUOTEDVALUE: str
11-
ATTRIBUTEVALUE: Any
12-
ATTRIBUTEVALUESPEC: Any
13-
ATTRIBUTE: Any
14-
OPENTAG: Any
15-
CLOSETAG: Any
16-
HTMLCOMMENT: str
17-
PROCESSINGINSTRUCTION: str
18-
DECLARATION: Any
19-
CDATA: str
20-
HTMLTAG: Any
21-
reHtmlTag: Any
22-
reBackslashOrAmp: Any
23-
ESCAPABLE: str
24-
reEntityOrEscapedChar: Any
25-
XMLSPECIAL: str
26-
reXmlSpecial: Any
6+
ENTITY: Final[str]
7+
TAGNAME: Final[str]
8+
ATTRIBUTENAME: Final[str]
9+
UNQUOTEDVALUE: Final[str]
10+
SINGLEQUOTEDVALUE: Final[str]
11+
DOUBLEQUOTEDVALUE: Final[str]
12+
ATTRIBUTEVALUE: Final[str]
13+
ATTRIBUTEVALUESPEC: Final[str]
14+
ATTRIBUTE: Final[str]
15+
OPENTAG: Final[str]
16+
CLOSETAG: Final[str]
17+
HTMLCOMMENT: Final[str]
18+
PROCESSINGINSTRUCTION: Final[str]
19+
DECLARATION: Final[str]
20+
CDATA: Final[str]
21+
HTMLTAG: Final[str]
22+
reHtmlTag: Final[re.Pattern[str]]
23+
reBackslashOrAmp: Final[re.Pattern[str]]
24+
ESCAPABLE: Final[str]
25+
reEntityOrEscapedChar: Final[re.Pattern[str]]
26+
XMLSPECIAL: Final[str]
27+
reXmlSpecial: Final[re.Pattern[str]]
2728

28-
def unescape_char(s): ...
29-
def unescape_string(s): ...
30-
def normalize_uri(uri): ...
29+
def unescape_char(s: AnyStr) -> AnyStr: ...
30+
def unescape_string(s: str) -> str: ...
31+
def normalize_uri(uri: str) -> str: ...
3132

32-
UNSAFE_MAP: Any
33+
UNSAFE_MAP: Final[dict[str, str]]
3334

34-
def replace_unsafe_char(s): ...
35-
def escape_xml(s): ...
35+
def replace_unsafe_char(s: str) -> str: ...
36+
@overload
37+
def escape_xml(s: None) -> Literal[""]: ...
38+
@overload
39+
def escape_xml(s: str) -> str: ...

stubs/commonmark/commonmark/dump.pyi

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1-
def prepare(obj, topnode: bool = ...): ...
2-
def dumpJSON(obj): ...
3-
def dumpAST(obj, ind: int = ..., topnode: bool = ...) -> None: ...
1+
from typing import Any
2+
3+
from .node import Node
4+
5+
def prepare(obj: Node, topnode: bool = ...) -> list[dict[str, Any]]: ...
6+
def dumpJSON(obj: Node) -> str: ...
7+
def dumpAST(obj: Node, ind: int = ..., topnode: bool = ...) -> None: ...

0 commit comments

Comments
 (0)