@@ -685,7 +685,9 @@ def show_pretty(self):
685685
686686 def get_abs_fnames_content (self ):
687687 # Sort files by last modified time (earliest first, latest last)
688- sorted_fnames = sorted (self .abs_fnames , key = lambda fname : os .path .getmtime (fname ))
688+ sorted_fnames = sorted (
689+ self .abs_fnames , key = lambda fname : os .path .exists (fname ) and os .path .getmtime (fname )
690+ )
689691
690692 for fname in sorted_fnames :
691693 content = self .io .read_text (fname )
@@ -743,8 +745,9 @@ def get_files_content(self, fnames=None):
743745 file_times = []
744746 for fname in fnames :
745747 try :
746- mtime = os .path .getmtime (fname )
747- file_times .append ((fname , mtime ))
748+ if os .path .exists (fname ):
749+ mtime = os .path .getmtime (fname )
750+ file_times .append ((fname , mtime ))
748751 except OSError :
749752 # Skip files that can't be accessed
750753 continue
@@ -840,7 +843,10 @@ def get_files_content(self, fnames=None):
840843 def get_read_only_files_content (self ):
841844 prompt = ""
842845 # Sort read-only files by last modified time (earliest first, latest last)
843- sorted_fnames = sorted (self .abs_read_only_fnames , key = lambda fname : os .path .getmtime (fname ))
846+ sorted_fnames = sorted (
847+ self .abs_read_only_fnames ,
848+ key = lambda fname : os .path .exists (fname ) and os .path .getmtime (fname ),
849+ )
844850
845851 # Handle regular read-only files
846852 for fname in sorted_fnames :
@@ -890,7 +896,8 @@ def get_read_only_files_content(self):
890896
891897 # Sort stub files by last modified time (earliest first, latest last)
892898 sorted_stub_fnames = sorted (
893- self .abs_read_only_stubs_fnames , key = lambda fname : os .path .getmtime (fname )
899+ self .abs_read_only_stubs_fnames ,
900+ key = lambda fname : os .path .exists (fname ) and os .path .getmtime (fname ),
894901 )
895902
896903 # Handle stub files
0 commit comments