diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2017-09-25 21:55:55 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-25 21:55:55 (GMT) |
commit | 81108375d9b2ccd0add1572da745311d4dfac505 (patch) | |
tree | 54632e1d6ec58850f70941452634c4faf1ea7218 /Lib/os.py | |
parent | f1502d097c29b266a5748312ee2451a2d6ac0af6 (diff) | |
download | cpython-81108375d9b2ccd0add1572da745311d4dfac505.zip cpython-81108375d9b2ccd0add1572da745311d4dfac505.tar.gz cpython-81108375d9b2ccd0add1572da745311d4dfac505.tar.bz2 |
bpo-30152: Reduce the number of imports for argparse. (#1269)
Diffstat (limited to 'Lib/os.py')
-rw-r--r-- | Lib/os.py | 21 |
1 files changed, 9 insertions, 12 deletions
@@ -23,7 +23,7 @@ and opendir), and leave all pathname manipulation to os.path #' import abc -import sys, errno +import sys import stat as st _names = sys.builtin_module_names @@ -590,12 +590,10 @@ def _execvpe(file, args, env=None): argrest = (args,) env = environ - head, tail = path.split(file) - if head: + if path.dirname(file): exec_func(file, *argrest) return - last_exc = saved_exc = None - saved_tb = None + saved_exc = None path_list = get_exec_path(env) if name != 'nt': file = fsencode(file) @@ -604,16 +602,15 @@ def _execvpe(file, args, env=None): fullname = path.join(dir, file) try: exec_func(fullname, *argrest) + except (FileNotFoundError, NotADirectoryError) as e: + last_exc = e except OSError as e: last_exc = e - tb = sys.exc_info()[2] - if (e.errno != errno.ENOENT and e.errno != errno.ENOTDIR - and saved_exc is None): + if saved_exc is None: saved_exc = e - saved_tb = tb - if saved_exc: - raise saved_exc.with_traceback(saved_tb) - raise last_exc.with_traceback(tb) + if saved_exc is not None: + raise saved_exc + raise last_exc def get_exec_path(env=None): |