classification
Title: zipfile suprising "except DeprecationWarning:" block
Type: Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: vstinner
Priority: normal Keywords: patch

Created on 2020-01-16 09:38 by vstinner, last changed 2020-01-17 14:18 by vstinner. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 18027 merged vstinner, 2020-01-16 09:41
Messages (2)
msg360107 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-01-16 09:38
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@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.
msg360193 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2020-01-17 14:17
New changeset 1d3b0aaa54c56282c0a3e7fc396e5b1de8b1974e by Victor Stinner in branch 'master':
bpo-39356, zipfile: Remove code handling DeprecationWarning (GH-18027)
https://github.com/python/cpython/commit/1d3b0aaa54c56282c0a3e7fc396e5b1de8b1974e
History
Date User Action Args
2020-01-17 14:18:29vstinnersetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2020-01-17 14:17:56vstinnersetmessages: + msg360193
2020-01-16 09:41:08vstinnersetkeywords: + patch
stage: patch review
pull_requests: + pull_request17423
2020-01-16 09:38:13vstinnercreate