@@ -1712,7 +1712,13 @@ class BlockParser:
1712
1712
Iterator, yields Block objects.
1713
1713
"""
1714
1714
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 :
1716
1722
"""
1717
1723
"input" should be a str object
1718
1724
with embedded \n characters.
@@ -1730,15 +1736,15 @@ def __init__(self, input, language, *, verify=True):
1730
1736
self .find_start_re = create_regex (before , after , whole_line = False )
1731
1737
self .start_re = create_regex (before , after )
1732
1738
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
1736
1742
self .first_block = True
1737
1743
1738
- def __iter__ (self ):
1744
+ def __iter__ (self ) -> BlockParser :
1739
1745
return self
1740
1746
1741
- def __next__ (self ):
1747
+ def __next__ (self ) -> Block :
1742
1748
while True :
1743
1749
if not self .input :
1744
1750
raise StopIteration
@@ -1755,18 +1761,18 @@ def __next__(self):
1755
1761
return block
1756
1762
1757
1763
1758
- def is_start_line (self , line ) :
1764
+ def is_start_line (self , line : str ) -> str | None :
1759
1765
match = self .start_re .match (line .lstrip ())
1760
1766
return match .group (1 ) if match else None
1761
1767
1762
- def _line (self , lookahead = False ):
1768
+ def _line (self , lookahead : bool = False ) -> str :
1763
1769
self .line_number += 1
1764
1770
line = self .input .pop ()
1765
1771
if not lookahead :
1766
1772
self .language .parse_line (line )
1767
1773
return line
1768
1774
1769
- def parse_verbatim_block (self ):
1775
+ def parse_verbatim_block (self ) -> Block :
1770
1776
add , output = text_accumulator ()
1771
1777
self .block_start_line_number = self .line_number
1772
1778
@@ -1780,13 +1786,13 @@ def parse_verbatim_block(self):
1780
1786
1781
1787
return Block (output ())
1782
1788
1783
- def parse_clinic_block (self , dsl_name ) :
1789
+ def parse_clinic_block (self , dsl_name : str ) -> Block :
1784
1790
input_add , input_output = text_accumulator ()
1785
1791
self .block_start_line_number = self .line_number + 1
1786
1792
stop_line = self .language .stop_line .format (dsl_name = dsl_name )
1787
1793
body_prefix = self .language .body_prefix .format (dsl_name = dsl_name )
1788
1794
1789
- def is_stop_line (line ) :
1795
+ def is_stop_line (line : str ) -> bool :
1790
1796
# make sure to recognize stop line even if it
1791
1797
# doesn't end with EOL (it could be the very end of the file)
1792
1798
if line .startswith (stop_line ):
@@ -1820,6 +1826,7 @@ def is_stop_line(line):
1820
1826
checksum_re = create_regex (before , after , word = False )
1821
1827
self .last_dsl_name = dsl_name
1822
1828
self .last_checksum_re = checksum_re
1829
+ assert checksum_re is not None
1823
1830
1824
1831
# scan forward for checksum line
1825
1832
output_add , output_output = text_accumulator ()
@@ -1834,6 +1841,7 @@ def is_stop_line(line):
1834
1841
if self .is_start_line (line ):
1835
1842
break
1836
1843
1844
+ output : str | None
1837
1845
output = output_output ()
1838
1846
if arguments :
1839
1847
d = {}
0 commit comments