Description
Documentation
100% of the essential information
The docstring for zipfile.ZipFile.write()
states
Put the bytes from filename into the archive under the name arcname.
See the code.
I conservatively propose
Read the bytes from filename on the disk and write the bytes to arcname in the archive.
I suggest changing arcname: StrPath
to arcname: str
.
^ 100% of the essential information, above
Explanation
(After I wrote the following, I discovered that apkfile has the same help text, so I assume the docstring was inherited from another source.)
Deconstructing the current text
"Put the bytes from filename into the archive under the name arcname."
- "under the name arcname" is a dangling modifier.
- "Put" is ambiguous: prefer precision to synonyms.
- "from/into" is a pretty good pair of contrasting words. And "from/to" is a little better. Furthermore, by rewriting the sentence to use "to" instead of "into", you will likely improve the sentence's clarity.
Conservative proposal and analysis
Read the bytes from filename on the disk and write the bytes to arcname in the archive.
Note the use of "mirrored" language and parallel language in the two clauses.
Read the bytes from filename on the disk and
write the bytes to arcname in the archive.
-
Read/write: contrast.
-
the bytes/the bytes: parallel "construction" because the objects are identical. In general: same name = same object; different name = different object.
- As opposed to "Read the bytes from filename on the disk and write them to arcname in the archive."
- the bytes/them: not parallel construction, so it is less clear if the objects are the same or different.
- Also consider, "Read the bytes from filename on the disk and write said bytes to arcname in the archive."
- the bytes/said bytes: not parallel construction, so it is less clear if the objects are the same or different.
- As opposed to "Read the bytes from filename on the disk and write them to arcname in the archive."
-
from/to: contrast.
-
filename/arcname: contrast.
-
on/in: contrast.
-
disk/archive: contrast.
-
At the "meta" level of the two clauses, filename and arcname are in the same position, so it tells us they are the same object.
Room for improvement
While "the disk" refers to a general concept, "the archive" refers to the highly specific object to which the method is attached. But there are not any signals to indicate this.
Similarly, the words "filename" and "arcname" are referring to syntax, which are specific objects, not general concepts. But there are not any signals to indicate this.
A possible improvement that doesn't require special markup is to use backticks
to reference syntax elements.
Read the bytes from
filename
on the disk and write the bytes toarcname
in the archive.
Side note
arcname: StrPath
StrPath = Union[str, os.PathLike[str]]
class PathLike(abc.ABC): Abstract base class for implementing the file system path protocol.
(I don't know where the code "declares" arcname is of type StrPath.)
Since arcname is merely used as a string and not to implement the file system path protocol, it might not be a PathLike object, so perhaps arcname: str
.
My motivation
I'm suggesting a change because I misinterpreted the documentation the first five or six times I read it. I thought arcname was the path to the archive, not the name of the file in the archive.
Summary
A conservative change
Read the bytes from filename on the disk and write the bytes to arcname in the archive.
A progressive change
arcname: str
Read the bytes fromfilename
on the disk and write the bytes toarcname
in the archive.
Metadata
Metadata
Assignees
Projects
Status