77from __future__ import annotations
88
99import random
10- from typing import TYPE_CHECKING , Any , Dict , List , Optional , Tuple , Type , TypeVar
10+ from typing import TYPE_CHECKING , Any , Dict , List , Optional , Tuple , Type , TypeVar , cast
1111
1212import numpy as np
1313import pandas as pd
@@ -502,6 +502,7 @@ def _visualize(
502502 scores = sorted_df .head (num_images )[get_score_colname (issue_type )]
503503 indices = scores .index .tolist ()
504504 images = [self ._dataset [i ] for i in indices ]
505+ images = cast (list [Image .Image ], images )
505506
506507 # construct title info
507508 title_info = {"scores" : [f"score : { x :.4f} " for x in scores ]}
@@ -526,6 +527,7 @@ def _visualize(
526527 image_sets = []
527528 for indices in image_sets_indices :
528529 image_sets .append ([self ._dataset [index ] for index in indices ])
530+ image_sets = cast (list [list [Image .Image ]], image_sets )
529531
530532 title_info_sets = []
531533 for s in image_sets_indices :
@@ -620,7 +622,7 @@ def visualize(
620622 elif image_files is not None :
621623 if len (image_files ) == 0 :
622624 raise ValueError ("image_files list is empty." )
623- images = [Image .open (path ) for path in image_files ]
625+ images : List [ Image . Image ] = [Image .open (path ) for path in image_files ]
624626 title_info = {"path" : [path .split ("/" )[- 1 ] for path in image_files ]}
625627 VizManager .individual_images (
626628 images ,
@@ -629,7 +631,7 @@ def visualize(
629631 cell_size = cell_size ,
630632 )
631633 elif indices :
632- images = [self ._dataset [i ] for i in indices ]
634+ images = [cast ( Image . Image , self ._dataset [i ]) for i in indices ]
633635 title_info = {"name" : [self ._dataset .get_name (i ) for i in indices ]}
634636 VizManager .individual_images (
635637 images ,
@@ -644,7 +646,7 @@ def visualize(
644646 image_indices = random .sample (
645647 self ._dataset .index , min (num_images , len (self ._dataset ))
646648 )
647- images = [self ._dataset [i ] for i in image_indices ]
649+ images = [cast ( Image . Image , self ._dataset [i ]) for i in image_indices ]
648650 title_info = {
649651 "name" : [self ._dataset .get_name (i ) for i in image_indices ]
650652 }
0 commit comments