2323#                  https://www.gnu.org/licenses/ 
2424# **************************************************************************** 
2525
26- import  io 
26+ import  atexit 
2727import  os 
2828import  tempfile 
29- 
30- import  atexit 
29+ from  typing  import  IO 
3130
3231# Until tmp_dir() and tmp_filename() are removed, we use this directory 
3332# as the parent for all temporary files & directories created by them. 
4140# temporary directory 
4241################################################################# 
4342
44- def  tmp_dir (name = 'dir_' , ext = '' ):
43+ def  tmp_dir (name = 'dir_' , ext = '' )  ->   str :
4544    r""" 
4645    Create and return a temporary directory in 
4746    ``$HOME/.sage/temp/hostname/pid/`` 
@@ -84,7 +83,7 @@ def tmp_dir(name='dir_', ext=''):
8483# temporary filename 
8584################################################################# 
8685
87- def  tmp_filename (name = 'tmp_' , ext = '' ):
86+ def  tmp_filename (name = 'tmp_' , ext = '' )  ->   str :
8887    r""" 
8988    Create and return a temporary file in 
9089    ``$HOME/.sage/temp/hostname/pid/`` 
@@ -163,8 +162,8 @@ class atomic_write:
163162      mode bits of the file were changed manually). (Not to be confused with 
164163      the file opening mode.) 
165164
166-     - ``binary`` -- boolean (default: ``True`` on Python 2, `` False`` on Python  
167-       3);  the underlying file is opened in binary mode.  If ``False`` then it is 
165+     - ``binary`` -- boolean (default: ``False``);  
166+       the underlying file is opened in binary mode.  If ``False`` then it is 
168167      opened in text mode and an encoding with which to write the file may be 
169168      supplied. 
170169
@@ -299,7 +298,7 @@ class atomic_write:
299298        False 
300299    """ 
301300    def  __init__ (self , target_filename , append = False , mode = 0o666 ,
302-                  binary = None , ** kwargs ):
301+                  binary = False , ** kwargs )  ->   None :
303302        """ 
304303        TESTS:: 
305304
@@ -320,13 +319,11 @@ def __init__(self, target_filename, append=False, mode=0o666,
320319        os .umask (umask )
321320        self .mode  =  mode  &  (~ umask )
322321
323-         # 'binary' mode is the default on Python 2, whereas 'text' mode is the 
324-         # default on Python 3--this reflects consistent handling of the default 
325-         # str type on the two platforms 
326-         self .binary  =  False  if  binary  is  None  else  binary 
322+         # 'text' mode is the default on Python 3 
323+         self .binary  =  binary 
327324        self .kwargs  =  kwargs 
328325
329-     def  __enter__ (self ):
326+     def  __enter__ (self )  ->   IO :
330327        """ 
331328        Create and return a temporary file in ``self.tmpdir`` (normally 
332329        the same directory as the target file). 
@@ -372,7 +369,7 @@ def __enter__(self):
372369
373370        return  self .tempfile 
374371
375-     def  __exit__ (self , exc_type , exc_val , exc_tb ):
372+     def  __exit__ (self , exc_type , exc_val , exc_tb )  ->   None :
376373        """ 
377374        If the ``with`` block was successful, move the temporary file 
378375        to the target file. Otherwise, delete the temporary file. 
@@ -457,7 +454,7 @@ class atomic_dir:
457454        ....:     h.read() 
458455        'Second' 
459456    """ 
460-     def  __init__ (self , target_directory ):
457+     def  __init__ (self , target_directory )  ->   None :
461458        r""" 
462459        TESTS:: 
463460
@@ -492,7 +489,7 @@ def __enter__(self):
492489        self .tempname  =  os .path .abspath (tdir .name )
493490        return  tdir 
494491
495-     def  __exit__ (self , exc_type , exc_val , exc_tb ):
492+     def  __exit__ (self , exc_type , exc_val , exc_tb )  ->   None :
496493        """ 
497494        If the ``with`` block was successful, move the temporary directory 
498495        to the target directory. Otherwise, delete the temporary directory. 
@@ -518,7 +515,8 @@ def __exit__(self, exc_type, exc_val, exc_tb):
518515            try :
519516                os .rename (self .tempname , self .target )
520517            except  OSError :
521-                 # Race: Another thread or process must have created the directory 
518+                 # Race: Another thread or process must have created 
519+                 # the directory 
522520                pass 
523521        else :
524522            # Failure: delete temporary file 
@@ -528,7 +526,7 @@ def __exit__(self, exc_type, exc_val, exc_tb):
528526_spyx_tmp  =  None 
529527
530528
531- def  spyx_tmp ():
529+ def  spyx_tmp ()  ->   str :
532530    r""" 
533531    The temporary directory used to store pyx files. 
534532
0 commit comments