1414from __future__ import annotations
1515
1616from operator import itemgetter
17- from typing import TYPE_CHECKING , Callable , Iterable , NamedTuple , cast
17+ from typing import (
18+ TYPE_CHECKING ,
19+ Callable ,
20+ Iterable ,
21+ Mapping ,
22+ NamedTuple ,
23+ Sequence ,
24+ cast ,
25+ )
1826
1927import rich .repr
2028from rich .console import Console , ConsoleOptions , RenderableType , RenderResult
@@ -105,7 +113,7 @@ class ChopsUpdate:
105113
106114 def __init__ (
107115 self ,
108- chops : list [ dict [int , Strip | None ]],
116+ chops : Sequence [ Mapping [int , Strip | None ]],
109117 spans : list [tuple [int , int , int ]],
110118 chop_ends : list [list [int ]],
111119 ) -> None :
@@ -876,7 +884,7 @@ def _render_chops(
876884 self ,
877885 crop : Region ,
878886 is_rendered_line : Callable [[int ], bool ],
879- ) -> list [ dict [int , Strip | None ]]:
887+ ) -> Sequence [ Mapping [int , Strip | None ]]:
880888 """Render update 'chops'.
881889
882890 Args:
@@ -907,10 +915,8 @@ def _render_chops(
907915 chops_line = chops [y ]
908916
909917 first_cut , last_cut = render_region .column_span
910- cuts_line = cuts [y ]
911- final_cuts = [
912- cut for cut in cuts_line if (last_cut >= cut >= first_cut )
913- ]
918+ final_cuts = [cut for cut in cuts [y ] if (last_cut >= cut >= first_cut )]
919+
914920 if len (final_cuts ) <= 2 :
915921 # Two cuts, which means the entire line
916922 cut_strips = [strip ]
@@ -920,8 +926,9 @@ def _render_chops(
920926 cut_strips = strip .divide (relative_cuts )
921927
922928 # Since we are painting front to back, the first segments for a cut "wins"
929+ get_chops_line = chops_line .get
923930 for cut , strip in zip (final_cuts , cut_strips ):
924- if chops_line [ cut ] is None :
931+ if get_chops_line ( cut ) is None :
925932 chops_line [cut ] = strip
926933
927934 return chops
0 commit comments