Skip to content

Commit bbf6297

Browse files
gh-104050: Argument Clinic: Annotate BlockParser (#106750)
1 parent 2d7d1aa commit bbf6297

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

Tools/clinic/clinic.py

+19-11
Original file line numberDiff line numberDiff line change
@@ -1712,7 +1712,13 @@ class BlockParser:
17121712
Iterator, yields Block objects.
17131713
"""
17141714

1715-
def __init__(self, input, language, *, verify=True):
1715+
def __init__(
1716+
self,
1717+
input: str,
1718+
language: Language,
1719+
*,
1720+
verify: bool = True
1721+
) -> None:
17161722
"""
17171723
"input" should be a str object
17181724
with embedded \n characters.
@@ -1730,15 +1736,15 @@ def __init__(self, input, language, *, verify=True):
17301736
self.find_start_re = create_regex(before, after, whole_line=False)
17311737
self.start_re = create_regex(before, after)
17321738
self.verify = verify
1733-
self.last_checksum_re = None
1734-
self.last_dsl_name = None
1735-
self.dsl_name = None
1739+
self.last_checksum_re: re.Pattern[str] | None = None
1740+
self.last_dsl_name: str | None = None
1741+
self.dsl_name: str | None = None
17361742
self.first_block = True
17371743

1738-
def __iter__(self):
1744+
def __iter__(self) -> BlockParser:
17391745
return self
17401746

1741-
def __next__(self):
1747+
def __next__(self) -> Block:
17421748
while True:
17431749
if not self.input:
17441750
raise StopIteration
@@ -1755,18 +1761,18 @@ def __next__(self):
17551761
return block
17561762

17571763

1758-
def is_start_line(self, line):
1764+
def is_start_line(self, line: str) -> str | None:
17591765
match = self.start_re.match(line.lstrip())
17601766
return match.group(1) if match else None
17611767

1762-
def _line(self, lookahead=False):
1768+
def _line(self, lookahead: bool = False) -> str:
17631769
self.line_number += 1
17641770
line = self.input.pop()
17651771
if not lookahead:
17661772
self.language.parse_line(line)
17671773
return line
17681774

1769-
def parse_verbatim_block(self):
1775+
def parse_verbatim_block(self) -> Block:
17701776
add, output = text_accumulator()
17711777
self.block_start_line_number = self.line_number
17721778

@@ -1780,13 +1786,13 @@ def parse_verbatim_block(self):
17801786

17811787
return Block(output())
17821788

1783-
def parse_clinic_block(self, dsl_name):
1789+
def parse_clinic_block(self, dsl_name: str) -> Block:
17841790
input_add, input_output = text_accumulator()
17851791
self.block_start_line_number = self.line_number + 1
17861792
stop_line = self.language.stop_line.format(dsl_name=dsl_name)
17871793
body_prefix = self.language.body_prefix.format(dsl_name=dsl_name)
17881794

1789-
def is_stop_line(line):
1795+
def is_stop_line(line: str) -> bool:
17901796
# make sure to recognize stop line even if it
17911797
# doesn't end with EOL (it could be the very end of the file)
17921798
if line.startswith(stop_line):
@@ -1820,6 +1826,7 @@ def is_stop_line(line):
18201826
checksum_re = create_regex(before, after, word=False)
18211827
self.last_dsl_name = dsl_name
18221828
self.last_checksum_re = checksum_re
1829+
assert checksum_re is not None
18231830

18241831
# scan forward for checksum line
18251832
output_add, output_output = text_accumulator()
@@ -1834,6 +1841,7 @@ def is_stop_line(line):
18341841
if self.is_start_line(line):
18351842
break
18361843

1844+
output: str | None
18371845
output = output_output()
18381846
if arguments:
18391847
d = {}

0 commit comments

Comments
 (0)