]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-126565: Skip `zipfile.Path.exists` check in write mode (#126576)
authorJan Hicken <janhicken@users.noreply.github.com>
Sun, 10 Nov 2024 14:57:24 +0000 (15:57 +0100)
committerGitHub <noreply@github.com>
Sun, 10 Nov 2024 14:57:24 +0000 (09:57 -0500)
commit160758a574d12bf0d965d8206136e7da4f4fd6c3
tree1c3d94bd8c6c80738334ae0bbc64bd70081846e7
parent450db61a78989c5a1f1106be01e071798c783cf9
gh-126565: Skip `zipfile.Path.exists` check in write mode (#126576)

When `zipfile.Path.open` is called, the implementation will check
whether the path already exists in the ZIP file. However, this check is
only required when the ZIP file is in read mode. By swapping arguments
of the `and` operator, the short-circuiting will prevent the check from
being run in write mode.

This change will improve the performance of `open()`, because checking
whether a file exists is slow in write mode, especially when the archive
has many members.
Lib/zipfile/_path/__init__.py
Misc/NEWS.d/next/Library/2024-11-08-11-06-14.gh-issue-126565.dFFO22.rst [new file with mode: 0644]