Skip to content

Commit 4549de1

Browse files
committed
Use mkstemp unconditionally. mktemp has been deprecated since Python 2.3.
1 parent e5b06e1 commit 4549de1

File tree

1 file changed

+3
-12
lines changed

1 file changed

+3
-12
lines changed

distutils/util.py

+3-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import subprocess
1313
import sys
1414
import sysconfig
15+
import tempfile
1516

1617
from ._log import log
1718
from ._modified import newer
@@ -405,20 +406,10 @@ def byte_compile( # noqa: C901
405406
# "Indirect" byte-compilation: write a temporary script and then
406407
# run it with the appropriate flags.
407408
if not direct:
408-
try:
409-
from tempfile import mkstemp
410-
411-
(script_fd, script_name) = mkstemp(".py")
412-
except ImportError:
413-
from tempfile import mktemp
414-
415-
(script_fd, script_name) = None, mktemp(".py")
409+
(script_fd, script_name) = tempfile.mkstemp(".py")
416410
log.info("writing byte-compilation script '%s'", script_name)
417411
if not dry_run:
418-
if script_fd is not None:
419-
script = os.fdopen(script_fd, "w", encoding='utf-8')
420-
else: # pragma: no cover
421-
script = open(script_name, "w", encoding='utf-8')
412+
script = os.fdopen(script_fd, "w", encoding='utf-8')
422413

423414
with script:
424415
script.write(

0 commit comments

Comments
 (0)