Skip to content

Commit 7922b67

Browse files
authored
pythongh-81954: Use lazy import warnings in zipfile (python#155326)
Since there is "lazy import warnings" at top level, it's no longer needed to import warnings explicitly in other places.
1 parent 3e12d54 commit 7922b67

1 file changed

Lines changed: 0 additions & 4 deletions

File tree

Lib/zipfile/__init__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,6 @@ def _decodeExtra(self, filename_crc):
620620
if up_unicode_name:
621621
self.filename = _sanitize_filename(up_unicode_name)
622622
else:
623-
import warnings
624623
warnings.warn("Empty unicode path extra field (0x7075)", stacklevel=2)
625624
except struct.error as e:
626625
raise BadZipFile("Corrupt unicode path extra field (0x7075)") from e
@@ -2153,7 +2152,6 @@ def comment(self, comment):
21532152
raise TypeError("comment: expected bytes, got %s" % type(comment).__name__)
21542153
# check for valid comment length
21552154
if len(comment) > ZIP_MAX_COMMENT:
2156-
import warnings
21572155
warnings.warn('Archive comment is too long; truncating to %d bytes'
21582156
% ZIP_MAX_COMMENT, stacklevel=2)
21592157
comment = comment[:ZIP_MAX_COMMENT]
@@ -2244,7 +2242,6 @@ def open(self, name, mode="r", pwd=None, *, force_zip64=False):
22442242
if (zinfo._end_offset is not None and
22452243
zef_file.tell() + zinfo.compress_size > zinfo._end_offset):
22462244
if zinfo._end_offset == zinfo.header_offset:
2247-
import warnings
22482245
warnings.warn(
22492246
f"Overlapped entries: {zinfo.orig_filename!r} "
22502247
f"(possible zip bomb)",
@@ -2494,7 +2491,6 @@ def _extract_member(self, member, targetpath, pwd):
24942491
def _writecheck(self, zinfo):
24952492
"""Check for errors before writing a file to the archive."""
24962493
if zinfo.filename in self.NameToInfo:
2497-
import warnings
24982494
warnings.warn('Duplicate name: %r' % zinfo.filename, stacklevel=3)
24992495
if self.mode not in ('w', 'x', 'a'):
25002496
raise ValueError("write() requires mode 'w', 'x', or 'a'")

0 commit comments

Comments
 (0)