New submission from Matthew Zipay: 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. Patch including tests is attached. ---------- components: Library (Lib) files: zipfile.ZipInfo.patch keywords: patch messages: 258859 nosy: Matthew Zipay priority: normal severity: normal status: open title: zipfile.ZipInfo slots can raise unexpected AttributeError type: behavior versions: Python 3.5, Python 3.6 Added file: http://bugs.python.org/file41698/zipfile.ZipInfo.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue26185> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com