@@ -1037,17 +1037,20 @@ def get_terminal_size(fallback=(80, 24)):
10371037
10381038def which (cmd , mode = os .F_OK | os .X_OK , path = None ):
10391039 """Given a command, mode, and a PATH string, return the path which
1040- conforms to the given mode on the PATH, or None if there is no such file.
1041- `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result of
1042- os.environ.get("PATH"), or can be overridden with a custom search path."""
1040+ conforms to the given mode on the PATH, or None if there is no such
1041+ file.
1042+
1043+ `mode` defaults to os.F_OK | os.X_OK. `path` defaults to the result
1044+ of os.environ.get("PATH"), or can be overridden with a custom search
1045+ path.
1046+
1047+ """
10431048 # Check that a given file can be accessed with the correct mode.
10441049 # Additionally check that `file` is not a directory, as on Windows
10451050 # directories pass the os.access check.
10461051 def _access_check (fn , mode ):
1047- if (os .path .exists (fn ) and os .access (fn , mode )
1048- and not os .path .isdir (fn )):
1049- return True
1050- return False
1052+ return (os .path .exists (fn ) and os .access (fn , mode )
1053+ and not os .path .isdir (fn ))
10511054
10521055 # Short circuit. If we're given a full path which matches the mode
10531056 # and it exists, we're done here.
@@ -1066,8 +1069,9 @@ def _access_check(fn, mode):
10661069 # See if the given file matches any of the expected path extensions.
10671070 # This will allow us to short circuit when given "python.exe".
10681071 matches = [cmd for ext in pathext if cmd .lower ().endswith (ext .lower ())]
1069- # If it does match, only test that one, otherwise we have to try others.
1070- files = [cmd + ext .lower () for ext in pathext ] if not matches else [cmd ]
1072+ # If it does match, only test that one, otherwise we have to try
1073+ # others.
1074+ files = [cmd ] if matches else [cmd + ext .lower () for ext in pathext ]
10711075 else :
10721076 # On other platforms you don't have things like PATHEXT to tell you
10731077 # what file suffixes are executable, so just pass on cmd as-is.
0 commit comments