Skip to content

Commit 779a0dd

Browse files
committed
Defer importing tempfile
1 parent 086fa4a commit 779a0dd

4 files changed

Lines changed: 7 additions & 4 deletions

File tree

src/PIL/EpsImagePlugin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
import re
2727
import subprocess
2828
import sys
29-
import tempfile
3029
from typing import IO
3130

3231
from . import Image, ImageFile
@@ -92,6 +91,8 @@ def Ghostscript(
9291
res_x = 72.0 * width / (bbox[2] - bbox[0])
9392
res_y = 72.0 * height / (bbox[3] - bbox[1])
9493

94+
import tempfile
95+
9596
out_fd, outfile = tempfile.mkstemp()
9697
os.close(out_fd)
9798

src/PIL/Image.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
import re
3737
import struct
3838
import sys
39-
import tempfile
4039
import warnings
4140
from collections.abc import MutableMapping
4241
from enum import IntEnum
@@ -738,6 +737,8 @@ def _dump(
738737
if not filename.endswith(suffix):
739738
filename += suffix
740739
else:
740+
import tempfile
741+
741742
f, filename = tempfile.mkstemp(suffix)
742743
os.close(f)
743744

src/PIL/ImageGrab.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import shutil
2222
import subprocess
2323
import sys
24-
import tempfile
2524

2625
from . import Image
2726

@@ -40,6 +39,8 @@ def grab(
4039
scale_down: bool = False,
4140
) -> Image.Image:
4241
im: Image.Image
42+
import tempfile
43+
4344
if xdisplay is None:
4445
if sys.platform == "darwin":
4546
fh, filepath = tempfile.mkstemp(".png")

src/PIL/JpegImagePlugin.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import struct
4141
import subprocess
4242
import sys
43-
import tempfile
4443
import warnings
4544

4645
from . import Image, ImageFile
@@ -467,6 +466,7 @@ def draft(
467466

468467
def load_djpeg(self) -> None:
469468
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
469+
import tempfile
470470

471471
f, path = tempfile.mkstemp()
472472
os.close(f)

0 commit comments

Comments
 (0)