Skip to content

Documentation of zipfile.ZipFile().writestr() fails to mention that 'data' may also be bytes #76216

Closed

Description

@Daniel5148
BPO 32035
Nosy @serhiy-storchaka, @CuriousLearner, @miss-islington, @miss-islington
PRs
  • bpo-32035: Update zipfile doc #4698
  • bpo-32035: Update zipfile doc #4757
  • bpo-32035: Fix words about strings and bytes in zipfile documentation. #10592
  • [3.7] bpo-32035: Fix words about strings and bytes in zipfile documentation. (GH-10592) #10694
  • [3.6] bpo-32035: Fix words about strings and bytes in zipfile documentation. (GH-10592) #10695
  • 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 2018-11-25.10:16:20.563>
    created_at = <Date 2017-11-15.14:54:20.875>
    labels = ['easy', '3.8', 'type-feature', '3.7', 'docs']
    title = "Documentation of zipfile.ZipFile().writestr() fails to mention that 'data' may also be bytes"
    updated_at = <Date 2018-11-25.10:16:20.562>
    user = 'https://bugs.python.org/Daniel5148'

    bugs.python.org fields:

    activity = <Date 2018-11-25.10:16:20.562>
    actor = 'serhiy.storchaka'
    assignee = 'docs@python'
    closed = True
    closed_date = <Date 2018-11-25.10:16:20.563>
    closer = 'serhiy.storchaka'
    components = ['Documentation']
    creation = <Date 2017-11-15.14:54:20.875>
    creator = 'Daniel5148'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 32035
    keywords = ['patch', 'easy']
    message_count = 5.0
    messages = ['306271', '330057', '330059', '330384', '330386', '330387']
    nosy_count = 5.0
    nosy_names = ['docs@python', 'serhiy.storchaka', 'CuriousLearner', 'Daniel5148', 'miss-islington', 'miss-islington']
    pr_nums = ['4698', '4757', '10592', '10694', '10695']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue32035'
    versions = ['Python 3.6', 'Python 3.7', 'Python 3.8']

    Activity

    1. Daniel5148 commented on Nov 15, 2017

      Daniel5148mannequin
      MannequinAuthor

      The documentation for "ZipFile.writestr(zinfo_or_arcname, data[, compress_type])" says: "Write the string data to the archive; [...]"
      --> https://docs.python.org/3/library/zipfile.html

      I fails to mention that data could also be bytes.

      The source code does mention it however, that is how I found out:

      def writestr(self, zinfo_or_arcname, data, compress_type=None):
              """Write a file into the archive.  The contents is 'data', which
              may be either a 'str' or a 'bytes' instance; if it is a 'str',
              it is encoded as UTF-8 first.
              'zinfo_or_arcname' is either a ZipInfo instance or
              the name of the file in the archive."""

      I believe this should be added to the documentation as it's an important information to those who try to add non-UTF8 StringIO data to in-memory ZipFiles using BytesIO.

    2. added
      3.8 (EOL)
      3.7 (EOL)
      on Nov 15, 2017
    3. added
      docs
      on Nov 15, 2017
    4. added
      type-feature
      and removed
      3.8 (EOL)
      on Nov 15, 2017
    5. CuriousLearner commented on Nov 18, 2018

      @CuriousLearner
      Member

      The change in current PR is very minor and looks good enough that aligns the docs with the docstring and functionality of ZipFile.writestr as described.

      Can a core-contributor, please look at this?

      Also, I'm adding 3.8 for this change.

    6. serhiy-storchaka commented on Nov 18, 2018

      @serhiy-storchaka
      Member

      Since the docstring contains more information, it is better to just copy words from the docstring to the documentation.

      There are also other places where string is improperly used instead of bytes or the type is not specified. The note about file name encoding doesn't make sense in Python 3, since ZipFile.write() doesn't support bytes as a file name.

      PR 10592 fixed this.

    7. serhiy-storchaka commented on Nov 25, 2018

      @serhiy-storchaka
      Member

      New changeset 4bb186d by Serhiy Storchaka in branch 'master':
      bpo-32035: Fix words about strings and bytes in zipfile documentation. (GH-10592)
      4bb186d

    8. miss-islington commented on Nov 25, 2018

      @miss-islington
      Contributor

      New changeset af009fb by Miss Islington (bot) in branch '3.6':
      bpo-32035: Fix words about strings and bytes in zipfile documentation. (GH-10592)
      af009fb

    9. miss-islington commented on Nov 25, 2018

      @miss-islington
      Contributor

      New changeset 89a3087 by Miss Islington (bot) in branch '3.7':
      bpo-32035: Fix words about strings and bytes in zipfile documentation. (GH-10592)
      89a3087

    10. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)3.8 (EOL)docseasytype-feature

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions