[New-bugs-announce] [issue39356] zipfile suprising "except DeprecationWarning:" block

STINNER Victor report at bugs.python.org
Thu Jan 16 04:38:13 EST 2020


New submission from STINNER Victor <vstinner at python.org>:

Lib/zipfile.py contains the following code:

try:
    filename, flag_bits = zinfo._encodeFilenameFlags()
    centdir = struct.pack(structCentralDir,
                          stringCentralDir, create_version,
                          zinfo.create_system, extract_version, zinfo.reserved,
                          flag_bits, zinfo.compress_type, dostime, dosdate,
                          zinfo.CRC, compress_size, file_size,
                          len(filename), len(extra_data), len(zinfo.comment),
                          0, zinfo.internal_attr, zinfo.external_attr,
                          header_offset)
except DeprecationWarning:
    print((structCentralDir, stringCentralDir, create_version,
           zinfo.create_system, extract_version, zinfo.reserved,
           zinfo.flag_bits, zinfo.compress_type, dostime, dosdate,
           zinfo.CRC, compress_size, file_size,
           len(zinfo.filename), len(extra_data), len(zinfo.comment),
           0, zinfo.internal_attr, zinfo.external_attr,
           header_offset), file=sys.stderr)
    raise

It is not considered as good programmating method to put print() statement in production code: usually, it's only used for debugging :-)

The "except DeprecationWarning:" with its print has been added 12 years ago by:

commit bf02e3bb21b2d75cba4ce409a14ae64dbc2dd6d2
Author: Gregory P. Smith <greg at mad-scientist.com>
Date:   Wed Mar 19 03:14:41 2008 +0000

    Fix the struct module DeprecationWarnings that zipfile was triggering by
    removing all use of signed struct values.
    
    test_zipfile and test_zipfile64 pass.  no more warnings.

But I don't recall any complain about a DeprecationWarning on struct.pack() in zipfile.

I propose attached PR to remove it.

----------
components: Library (Lib)
messages: 360107
nosy: vstinner
priority: normal
severity: normal
status: open
title: zipfile suprising "except DeprecationWarning:" block
versions: Python 3.9

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39356>
_______________________________________


More information about the New-bugs-announce mailing list