Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zipfile suprising "except DeprecationWarning:" block #83537

Closed
vstinner opened this issue Jan 16, 2020 · 2 comments
Closed

zipfile suprising "except DeprecationWarning:" block #83537

vstinner opened this issue Jan 16, 2020 · 2 comments
Labels
3.9 only security fixes stdlib Python modules in the Lib dir

Comments

@vstinner
Copy link
Member

BPO 39356
Nosy @vstinner
PRs
  • bpo-39356, zipfile: Remove code handling DeprecationWarning #18027
  • 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:

    assignee = None
    closed_at = <Date 2020-01-17.14:18:29.944>
    created_at = <Date 2020-01-16.09:38:13.243>
    labels = ['library', '3.9']
    title = 'zipfile suprising "except DeprecationWarning:" block'
    updated_at = <Date 2020-01-17.14:18:29.943>
    user = 'https://github.com/vstinner'

    bugs.python.org fields:

    activity = <Date 2020-01-17.14:18:29.943>
    actor = 'vstinner'
    assignee = 'none'
    closed = True
    closed_date = <Date 2020-01-17.14:18:29.944>
    closer = 'vstinner'
    components = ['Library (Lib)']
    creation = <Date 2020-01-16.09:38:13.243>
    creator = 'vstinner'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 39356
    keywords = ['patch']
    message_count = 2.0
    messages = ['360107', '360193']
    nosy_count = 1.0
    nosy_names = ['vstinner']
    pr_nums = ['18027']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue39356'
    versions = ['Python 3.9']

    @vstinner
    Copy link
    Member Author

    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 bf02e3b
    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.

    @vstinner vstinner added 3.9 only security fixes stdlib Python modules in the Lib dir labels Jan 16, 2020
    @vstinner
    Copy link
    Member Author

    New changeset 1d3b0aa by Victor Stinner in branch 'master':
    bpo-39356, zipfile: Remove code handling DeprecationWarning (GH-18027)
    1d3b0aa

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.9 only security fixes stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant