66import os
77import time
88import json
9- from typing import TYPE_CHECKING , NamedTuple
9+ from typing import TYPE_CHECKING , Callable , NamedTuple
1010
1111import numpy as np
1212
@@ -257,7 +257,7 @@ def close(self) -> None:
257257 """Close the stats file handle if it is not /dev/null."""
258258 if self .stats_fh is not None and self .stats_fh .name != os .devnull :
259259 self .stats_fh .close ()
260- self .stats_fh = None
260+ self .stats_fh = None # type: ignore[assignment]
261261
262262 @classmethod
263263 def recompute (
@@ -316,7 +316,7 @@ def recompute(
316316 break
317317 kitty_scale -= 1
318318
319- def pos (img_h , img_w ) :
319+ def pos (img_h : int , img_w : int ) -> tuple [ int , int ] :
320320 rx = max (2 , (pixel_h - img_h ) // 2 // cell_h + 1 )
321321 ry = max (1 , (pixel_w - img_w ) // 2 // cell_w + 1 )
322322 return rx , ry
@@ -385,7 +385,7 @@ def blit_sixel(
385385 f"{ self .refx } ,{ self .refy } ,,,,,\n "
386386 )
387387 self .stats_fh .flush ()
388- return f"\033 [{ self .refx } ;{ self .refy } H\033 [0m" .encode () + result
388+ return f"\033 [{ self .refx } ;{ self .refy } H\033 [0m" .encode () + result # type: ignore[no-any-return]
389389
390390 total_pixels = video .size
391391 diff = video != self .sixel_baseline
@@ -404,7 +404,7 @@ def blit_sixel(
404404 f"{ self .refx } ,{ self .refy } ,,,,,\n "
405405 )
406406 self .stats_fh .flush ()
407- return f"\033 [{ self .refx } ;{ self .refy } H\033 [0m" .encode () + result
407+ return f"\033 [{ self .refx } ;{ self .refy } H\033 [0m" .encode () + result # type: ignore[no-any-return]
408408
409409 self .profile .deltas += 1
410410
@@ -439,7 +439,7 @@ def blit_sixel(
439439 )
440440 self .stats_fh .flush ()
441441
442- return f"\033 [{ self .refx } ;{ self .refy } H\033 [0m" .encode () + result
442+ return f"\033 [{ self .refx } ;{ self .refy } H\033 [0m" .encode () + result # type: ignore[no-any-return]
443443
444444 def blit_sixel_blitless (
445445 self ,
@@ -465,9 +465,13 @@ def blit_sixel_blitless(
465465 f"{ self .refx } ,{ self .refy } ,,,,,\n "
466466 )
467467 self .stats_fh .flush ()
468- return f"\033 [{ self .refx } ;{ self .refy } H\033 [0m" .encode () + result
468+ return f"\033 [{ self .refx } ;{ self .refy } H\033 [0m" .encode () + result # type: ignore[no-any-return]
469469
470- def encode_kitty_frame (self , video , encode_fn ):
470+ def encode_kitty_frame (
471+ self ,
472+ video : "np.ndarray" ,
473+ encode_fn : "Callable[..., bytes]" ,
474+ ) -> bytes :
471475 """Encode kitty frame: keyframe on first call, dirty-rect delta otherwise.
472476
473477 Deltas send the bounding box of changed pixels positioned via
@@ -499,11 +503,11 @@ def encode_kitty_frame(self, video, encode_fn):
499503 np .repeat (rgba , self .kitty_scale , axis = 0 ), self .kitty_scale , axis = 1
500504 )
501505 h , w = rgba .shape [:2 ]
502- result = [
506+ parts : list [ bytes ] = [
503507 f"\033 [{ self .refx_kitty } ;{ self .refy_kitty } H" .encode (),
504508 encode_fn (rgba .tobytes (), w , h , image_id = BASELINE_ID ),
505509 ]
506- result = b"" .join (result )
510+ result = b"" .join (parts )
507511 elapsed_us = int ((time .perf_counter () - t0 ) * 1e6 )
508512 self .stats_fh .write (
509513 f"{ n } ,0.0,first_keyframe,{ len (result )} ,{ elapsed_us } ,,,,,,,,,,,,,,\n "
@@ -537,14 +541,14 @@ def encode_kitty_frame(self, video, encode_fn):
537541 np .repeat (rgba , self .kitty_scale , axis = 0 ), self .kitty_scale , axis = 1
538542 )
539543 h , w = rgba .shape [:2 ]
540- result = [
544+ rebase_parts : list [ bytes ] = [
541545 f"\033 [{ self .refx_kitty } ;{ self .refy_kitty } H" .encode (),
542546 ]
543547 if self .had_delta :
544- result .append (f"\033 _Ga=d,d=i,i={ DELTA_ID } \033 \\ " .encode ())
545- result .append (encode_fn (rgba .tobytes (), w , h , image_id = BASELINE_ID ))
548+ rebase_parts .append (f"\033 _Ga=d,d=i,i={ DELTA_ID } \033 \\ " .encode ())
549+ rebase_parts .append (encode_fn (rgba .tobytes (), w , h , image_id = BASELINE_ID ))
546550 self .had_delta = False
547- result = b"" .join (result )
551+ result = b"" .join (rebase_parts )
548552 elapsed_us = int ((time .perf_counter () - t0 ) * 1e6 )
549553 self .stats_fh .write (
550554 f"{ n } ,{ changed_pct :.2f} ,rebaseline,{ len (result )} ,{ elapsed_us } ,,,,,,,,,,,,,,\n "
0 commit comments