Refactor loop to only calculate the full_path once

This commit is contained in:
Toshio Kuratomi 2015-02-26 16:01:42 -08:00
parent 68c99a12b3
commit 0f4b72cdfa

View file

@ -176,11 +176,10 @@ class PluginLoader(object):
found = None
for path in [p for p in self._get_paths() if p not in self._searched_paths]:
if os.path.isdir(path):
for potential_file in (f for f in os.listdir(path)
if os.path.isfile(os.path.join(path, f))):
full_paths = (os.path.join(path, f) for f in os.listdir(path))
for full_path in (f for f in full_paths if os.path.isfile(f)):
for suffix in suffixes:
if potential_file.endswith(suffix):
full_path = os.path.join(path, potential_file)
if full_path.endswith(suffix):
full_name = os.path.basename(full_path)
break
else: # Yes, this is a for-else: http://bit.ly/1ElPkyg