The zipfile.ZipInfo.__init__ method permits several of ZipInfo's slot attributes to go uninitialized unless the object is obtained from ZipFile.getinfo() or ZipFile.infolist().
As a result, accessing those attributes (header_offset, CRC, compress_size, or file_size) or attempting to repr() a ZipInfo object can fail unexpectedly with AttributeError. (I say "unexpectedly" because ZipInfo.__init__ and its attributes are public/documented, so the attributes ought to be properly initialized regardless of how the object gets created.)
A simple test to illustrate:
>>> import zipfile
>>> zinfo = zipfile.ZipInfo()
>>> repr(zinfo)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "********/cpython/Lib/zipfile.py", line 376, in __repr__
result.append(' file_size=%r' % self.file_size)
AttributeError: file_size
(If you assign zinfo.file_size = None, it next fails on compress_size.)
This problem has been noted before - see issues 3039 and 22217 - but has not been resolved.
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: