You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Documentation of zipfile.ZipFile().writestr() fails to mention that 'data' may also be bytes #76216
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=Noneclosed_at=<Date2018-11-25.10:16:20.563>created_at=<Date2017-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=<Date2018-11-25.10:16:20.562>user='https://bugs.python.org/Daniel5148'
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:
defwritestr(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.
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.
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.
New changeset 4bb186d by Serhiy Storchaka in branch 'master': bpo-32035: Fix words about strings and bytes in zipfile documentation. (GH-10592) 4bb186d
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
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
Activity
Daniel5148 commentedon Nov 15, 2017
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:
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.
CuriousLearner commentedon Nov 18, 2018
The change in current PR is very minor and looks good enough that aligns the docs with the docstring and functionality of
ZipFile.writestras described.Can a core-contributor, please look at this?
Also, I'm adding 3.8 for this change.
serhiy-storchaka commentedon Nov 18, 2018
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.
serhiy-storchaka commentedon Nov 25, 2018
New changeset 4bb186d by Serhiy Storchaka in branch 'master':
bpo-32035: Fix words about strings and bytes in zipfile documentation. (GH-10592)
4bb186d
miss-islington commentedon Nov 25, 2018
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
miss-islington commentedon Nov 25, 2018
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