@@ -297,12 +297,11 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
297297 -------
298298 f : file-like
299299 A file-like object
300- new_handle : file-like or None
301- A file-like object that was openned in this function. Or None if none
302- were openned.
300+ handles : list of file-like objects
301+ A list of file-like object that were openned in this function.
303302 """
304303
305- new_handle = None
304+ handles = list ()
306305 f = path_or_buf
307306 is_path = isinstance (path_or_buf , compat .string_types )
308307
@@ -358,13 +357,15 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
358357 msg = 'Unrecognized compression type: {}' .format (compression )
359358 raise ValueError (msg )
360359
360+ handles .append (f )
361+
361362 # In Python 3
362363 if compat .PY3 :
363364 from io import TextIOWrapper
364365 f = TextIOWrapper (f , encoding = encoding )
366+ handles .append (f )
365367
366- new_handle = f
367- return f , new_handle
368+ return f , handles
368369
369370 elif is_path :
370371 if compat .PY2 :
@@ -376,13 +377,13 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
376377 else :
377378 # Python 3 and no explicit encoding
378379 f = open (path_or_buf , mode , errors = 'replace' )
379- new_handle = f
380+ handles . append ( f )
380381
381382 # in Python 3, convert BytesIO or fileobjects passed with an encoding
382383 if compat .PY3 and isinstance (path_or_buf , compat .BytesIO ):
383384 from io import TextIOWrapper
384385 f = TextIOWrapper (f , encoding = encoding )
385- new_handle = f
386+ handles . append ( f )
386387
387388 if memory_map and hasattr (f , 'fileno' ):
388389 try :
@@ -396,7 +397,7 @@ def _get_handle(path_or_buf, mode, encoding=None, compression=None,
396397 # leave the file handler as is then
397398 pass
398399
399- return f , new_handle
400+ return f , handles
400401
401402
402403class MMapWrapper (BaseIterator ):
0 commit comments