11"""because list is complex, split list parser in a new file"""
2+ from __future__ import annotations
23
34import re
4- from typing import TYPE_CHECKING , Any , Dict , Iterable , List , Optional , Tuple , Match
5+ from typing import TYPE_CHECKING , cast , Any , Iterable , Optional , Match
56from .util import expand_leading_tab , expand_tab , strip_end
67
78if TYPE_CHECKING :
@@ -30,7 +31,7 @@ def parse_list(block: "BlockParser", m: Match[str], state: "BlockState") -> int:
3031 marker = m .group ("list_2" )
3132 ordered = len (marker ) > 1
3233 depth = state .depth ()
33- token : Dict [str , Any ] = {
34+ token : dict [str , Any ] = {
3435 "type" : "list" ,
3536 "children" : [],
3637 "tight" : True ,
@@ -51,7 +52,7 @@ def parse_list(block: "BlockParser", m: Match[str], state: "BlockState") -> int:
5152 token ["attrs" ]["start" ] = start
5253
5354 state .cursor = m .end () + 1
54- groups : Optional [Tuple [str , str , str ]] = (m .group ("list_1" ), marker , text )
55+ groups : Optional [tuple [str , str , str ]] = (m .group ("list_1" ), marker , text )
5556
5657 if depth >= block .max_nested_level - 1 :
5758 rules = list (block .list_rules )
@@ -68,13 +69,13 @@ def parse_list(block: "BlockParser", m: Match[str], state: "BlockState") -> int:
6869 if end_pos :
6970 index = token .pop ("_tok_index" )
7071 state .tokens .insert (index , token )
71- return end_pos
72+ return cast ( int , end_pos )
7273
7374 state .append_token (token )
7475 return state .cursor
7576
7677
77- def _transform_tight_list (token : Dict [str , Any ]) -> None :
78+ def _transform_tight_list (token : dict [str , Any ]) -> None :
7879 if token ["tight" ]:
7980 # reset tight list item
8081 for list_item in token ["children" ]:
@@ -88,11 +89,11 @@ def _transform_tight_list(token: Dict[str, Any]) -> None:
8889def _parse_list_item (
8990 block : "BlockParser" ,
9091 bullet : str ,
91- groups : Tuple [str , str , str ],
92- token : Dict [str , Any ],
92+ groups : tuple [str , str , str ],
93+ token : dict [str , Any ],
9394 state : "BlockState" ,
94- rules : List [str ],
95- ) -> Optional [ Tuple [ str , str , str ]] :
95+ rules : list [str ],
96+ ) -> tuple [ str , str , str ] | None :
9697 spaces , marker , text = groups
9798
9899 leading_width = len (spaces ) + len (marker )
@@ -216,7 +217,7 @@ def _compile_list_item_pattern(bullet: str, leading_width: int) -> str:
216217 )
217218
218219
219- def _compile_continue_width (text : str , leading_width : int ) -> Tuple [str , int ]:
220+ def _compile_continue_width (text : str , leading_width : int ) -> tuple [str , int ]:
220221 text = expand_leading_tab (text , 3 )
221222 text = expand_tab (text )
222223
@@ -255,7 +256,7 @@ def _clean_list_item_text(src: str, continue_width: int) -> str:
255256 return "\n " .join (rv )
256257
257258
258- def _is_loose_list (tokens : Iterable [Dict [str , Any ]]) -> bool :
259+ def _is_loose_list (tokens : Iterable [dict [str , Any ]]) -> bool :
259260 paragraph_count = 0
260261 for tok in tokens :
261262 if tok ["type" ] == "blank_line" :
0 commit comments