@@ -103,7 +103,7 @@ def looks_like_rst(value: str) -> bool:
103103 if re .search (directive .pattern , value ):
104104 return True
105105 # allow "text::" or "text ::" but not "^::$" or "^:::$"
106- return re .search (r'(\s|\w)::\n' , value ) or '\n >>> ' in value
106+ return bool ( re .search (r'(\s|\w)::\n' , value ) or '\n >>> ' in value )
107107
108108
109109class IBlockBeginning (SimpleNamespace ):
@@ -146,7 +146,7 @@ def finish_consumption(self, final: bool) -> str:
146146
147147class BlockParser (IParser ):
148148 enclosure = '```'
149- follower = None
149+ follower : Union [ 'IParser' , None ] = None
150150 _buffer : List [str ]
151151 _block_started : bool
152152
@@ -167,7 +167,7 @@ def consume(self, line: str):
167167 raise ValueError ('Block has not started' )
168168 self ._buffer .append (line )
169169
170- def finish_consumption (self , final : bool ):
170+ def finish_consumption (self , final : bool ) -> str :
171171 # if the last line is empty (e.g. a separator of intended block), discard it
172172 if self ._buffer [len (self ._buffer ) - 1 ].strip () == '' :
173173 self ._buffer .pop ()
@@ -196,7 +196,7 @@ def _start_block(self, language: str):
196196 def can_consume (self , line : str ) -> bool :
197197 if self ._is_block_beginning and line .strip () == '' :
198198 return True
199- return ( len (line ) > 0 and re .match (r'^\s' , line [0 ])) or len (line ) == 0
199+ return bool (( len (line ) > 0 and re .match (r'^\s' , line [0 ])) or len (line ) == 0 )
200200
201201 def consume (self , line : str ):
202202 if self ._is_block_beginning :
@@ -296,6 +296,8 @@ def can_parse(self, line: str) -> bool:
296296
297297 def initiate_parsing (self , line : str , current_language : str ) -> IBlockBeginning :
298298 match = re .match (CODE_BLOCK_PATTERN , line )
299+ # already checked in can_parse
300+ assert match
299301 self ._start_block (match .group ('language' ).strip () or current_language )
300302 return IBlockBeginning (remainder = '' )
301303
@@ -319,7 +321,7 @@ def initiate_parsing(self, line: str, current_language: str) -> IBlockBeginning:
319321]
320322
321323
322- def rst_to_markdown (text : str ):
324+ def rst_to_markdown (text : str ) -> str :
323325 """
324326 Try to parse docstrings in following formats to markdown:
325327 - https://www.python.org/dev/peps/pep-0287/
0 commit comments