Skip to content

Commit

Permalink
Reduce indentation with early exit
Browse files Browse the repository at this point in the history
  • Loading branch information
bwendling committed Feb 3, 2020
1 parent 2a5ddd3 commit 736e63f
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 28 deletions.
32 changes: 16 additions & 16 deletions yapf/yapflib/file_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ def _FindPythonFiles(filenames, recursive, exclude):
if filename != '.' and exclude and IsIgnored(filename, exclude):
continue
if os.path.isdir(filename):
if recursive:
# TODO(morbo): Look into a version of os.walk that can handle recursion.
excluded_dirs = []
for dirpath, _, filelist in os.walk(filename):
if dirpath != '.' and exclude and IsIgnored(dirpath, exclude):
excluded_dirs.append(dirpath)
continue
elif any(dirpath.startswith(e) for e in excluded_dirs):
continue
for f in filelist:
filepath = os.path.join(dirpath, f)
if exclude and IsIgnored(filepath, exclude):
continue
if IsPythonFile(filepath):
python_files.append(filepath)
else:
if not recursive:
raise errors.YapfError(
"directory specified without '--recursive' flag: %s" % filename)

# TODO(morbo): Look into a version of os.walk that can handle recursion.
excluded_dirs = []
for dirpath, _, filelist in os.walk(filename):
if dirpath != '.' and exclude and IsIgnored(dirpath, exclude):
excluded_dirs.append(dirpath)
continue
elif any(dirpath.startswith(e) for e in excluded_dirs):
continue
for f in filelist:
filepath = os.path.join(dirpath, f)
if exclude and IsIgnored(filepath, exclude):
continue
if IsPythonFile(filepath):
python_files.append(filepath)
elif os.path.isfile(filename):
python_files.append(filename)

Expand Down
24 changes: 12 additions & 12 deletions yapf/yapflib/split_penalty.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,20 @@ def Visit_power(self, node): # pylint: disable=invalid-name,missing-docstring
while prev_trailer_idx < len(node.children) - 1:
cur_trailer_idx = prev_trailer_idx + 1
cur_trailer = node.children[cur_trailer_idx]
if pytree_utils.NodeName(cur_trailer) == 'trailer':
# Now we know we have two trailers one after the other
prev_trailer = node.children[prev_trailer_idx]
if prev_trailer.children[-1].value != ')':
# Set the previous node unbreakable if it's not a function call:
# atom tr1() tr2
# It may be necessary (though undesirable) to split up a previous
# function call's parentheses to the next line.
_SetStronglyConnected(prev_trailer.children[-1])
_SetStronglyConnected(cur_trailer.children[0])
prev_trailer_idx = cur_trailer_idx
else:
if pytree_utils.NodeName(cur_trailer) != 'trailer':
break

# Now we know we have two trailers one after the other
prev_trailer = node.children[prev_trailer_idx]
if prev_trailer.children[-1].value != ')':
# Set the previous node unbreakable if it's not a function call:
# atom tr1() tr2
# It may be necessary (though undesirable) to split up a previous
# function call's parentheses to the next line.
_SetStronglyConnected(prev_trailer.children[-1])
_SetStronglyConnected(cur_trailer.children[0])
prev_trailer_idx = cur_trailer_idx

# We don't want to split before the last ')' of a function call. This also
# takes care of the special case of:
# atom tr1 tr2 ... trn
Expand Down

0 comments on commit 736e63f

Please sign in to comment.