[NumPy-Tickets] [NumPy] #2090: `npy_PyFile_Dup` should check file object subclass

NumPy Trac numpy-tickets@scipy....
Thu Mar 22 14:59:13 CDT 2012

#2090: `npy_PyFile_Dup` should check file object subclass
 Reporter:  pv            |       Owner:  somebody   
     Type:  defect        |      Status:  new        
 Priority:  normal        |   Milestone:  Unscheduled
Component:  numpy.core    |     Version:  1.6.1      
 Keywords:  py3 fromfile  |  
 Consider this on Python 3:
 import gzip
 import numpy as np
 f = gzip.open('foo.gz', 'wb')
 f.write(b"1 2 3")
 f = gzip.open('foo.gz', 'rb')
 print(np.fromfile(f, sep=' '))
 # -> [-1.]
 On Python 2 this fails with an IOError.

 The problem here is that `fromfile` seems to read the compressed stream.
 This is probably a bug in Python 3 --- `PyObject_AsFileDescriptor` when
 called on a `GzipFile` object does not fail (although there is no OS level
 file handle corresponding to the uncompressed stream!). As a workaround,
 `npy_PyFile_Dup` should probably check that the object passed in inherits
 from a suitable subclass in the io object hierarchy.

Ticket URL: <http://projects.scipy.org/numpy/ticket/2090>
NumPy <http://projects.scipy.org/numpy>
My example project

More information about the NumPy-Tickets mailing list