gh-81954: Use lazy import warnings in zipfile (#155326)
vstinner <[email protected]> Fri, 07 Aug 2026 13:15:46 -0400 (EDT)
| Newsgroups | gmane.comp.python.cvs |
|---|---|
| Message-ID | <[email protected]> |
https://github.com/python/cpython/commit/7922b673f217efbf23fd8a1f5df3c20d5dd8e96d commit: 7922b673f217efbf23fd8a1f5df3c20d5dd8e96d branch: main author: Victor Stinner <[email protected]> committer: vstinner <[email protected]> date: 2026-08-07T19:15:31+02:00 summary: gh-81954: Use lazy import warnings in zipfile (#155326) Since there is "lazy import warnings" at top level, it's no longer needed to import warnings explicitly in other places. files: M Lib/zipfile/__init__.py diff --git a/Lib/zipfile/__init__.py b/Lib/zipfile/__init__.py index 6c353b4ff850626..764bb9b1e9246f6 100644 --- a/Lib/zipfile/__init__.py +++ b/Lib/zipfile/__init__.py @@ -620,7 +620,6 @@ def _decodeExtra(self, filename_crc): if up_unicode_name: self.filename = _sanitize_filename(up_unicode_name) else: - import warnings warnings.warn("Empty unicode path extra field (0x7075)", stacklevel=2) except struct.error as e: raise BadZipFile("Corrupt unicode path extra field (0x7075)") from e @@ -2153,7 +2152,6 @@ def comment(self, comment): raise TypeError("comment: expected bytes, got %s" % type(comment).__name__) # check for valid comment length if len(comment) > ZIP_MAX_COMMENT: - import warnings warnings.warn('Archive comment is too long; truncating to %d bytes' % ZIP_MAX_COMMENT, stacklevel=2) comment = comment[:ZIP_MAX_COMMENT] @@ -2244,7 +2242,6 @@ def open(self, name, mode="r", pwd=None, *, force_zip64=False): if (zinfo._end_offset is not None and zef_file.tell() + zinfo.compress_size > zinfo._end_offset): if zinfo._end_offset == zinfo.header_offset: - import warnings warnings.warn( f"Overlapped entries: {zinfo.orig_filename!r} " f"(possible zip bomb)", @@ -2494,7 +2491,6 @@ def _extract_member(self, member, targetpath, pwd): def _writecheck(self, zinfo): """Check for errors before writing a file to the archive.""" if zinfo.filename in self.NameToInfo: - import warnings warnings.warn('Duplicate name: %r' % zinfo.filename, stacklevel=3) if self.mode not in ('w', 'x', 'a'): raise ValueError("write() requires mode 'w', 'x', or 'a'") _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]