Skip to content

Commit

Permalink
Fix no-else-return lint violations.
Browse files Browse the repository at this point in the history
Also cleans up some stylistic things.

PiperOrigin-RevId: 153106607
Change-Id: Id418ab8a2bd13cd983b6f2d9d285fa3e677fa650
Reviewed-on: https://team-review.git.corp.google.com/68304
Reviewed-by: David Bieber <[email protected]>
  • Loading branch information
dbieber committed Apr 17, 2017
1 parent 3b04b0e commit d998200
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 28 deletions.
2 changes: 0 additions & 2 deletions doc/using-cli.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# Using a Fire CLI



## Basic usage

Every Fire command corresponds to a Python component.
Expand Down
17 changes: 8 additions & 9 deletions fire/completion.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,18 +160,17 @@ def Completions(component, verbose=False):
spec = inspectutils.GetFullArgSpec(component)
return _CompletionsFromArgs(spec.args + spec.kwonlyargs)

elif isinstance(component, (tuple, list)):
if isinstance(component, (tuple, list)):
return [str(index) for index in range(len(component))]

elif inspect.isgenerator(component):
if inspect.isgenerator(component):
# TODO: There are currently no commands available for generators.
return []

else:
return [
_FormatForCommand(member_name)
for member_name, unused_member in _Members(component, verbose)
]
return [
_FormatForCommand(member_name)
for member_name, unused_member in _Members(component, verbose)
]


def _FormatForCommand(token):
Expand All @@ -192,8 +191,8 @@ def _FormatForCommand(token):

if token.startswith('_'):
return token
else:
return token.replace('_', '-')

return token.replace('_', '-')


def _Commands(component, depth=3):
Expand Down
3 changes: 1 addition & 2 deletions fire/fire_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,10 @@ def testFire(self):
self.assertEqual(fire.Fire(tc.OldStyleWithDefaults, 'double 2'), 4)
self.assertEqual(fire.Fire(tc.OldStyleWithDefaults, 'triple 4'), 12)

def testFireDefaultBaseName(self):
def testFireDefaultName(self):
with mock.patch.object(sys, 'argv',
[os.path.join('python-fire', 'fire',
'base_filename.py')]):
# positive case
with self.assertOutputMatches(stdout='Usage: base_filename.py',
stderr=None):
fire.Fire(tc.Empty)
Expand Down
16 changes: 7 additions & 9 deletions fire/helputils.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,17 +186,15 @@ def UsageString(component, trace=None, verbose=False):
spec = inspectutils.GetFullArgSpec(component)
return _UsageStringFromFullArgSpec(command, spec)

elif isinstance(component, (list, tuple)):
if isinstance(component, (list, tuple)):
length = len(component)
if length == 0:
return command
elif length == 1:
if length == 1:
return command + '[0]'
else:
return command + '[0..{cap}]'.format(cap=length - 1)
return command + '[0..{cap}]'.format(cap=length - 1)

else:
completions = completion.Completions(component, verbose)
if command:
completions = [''] + completions
return '\n'.join(command + end for end in completions)
completions = completion.Completions(component, verbose)
if command:
completions = [''] + completions
return '\n'.join(command + end for end in completions)
3 changes: 1 addition & 2 deletions fire/inspectutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,7 @@ def GetFullArgSpec(fn):
# Are there other cases?
if inspect.isbuiltin(fn):
return FullArgSpec(varargs='vars', varkw='kwargs')
else:
return FullArgSpec()
return FullArgSpec()

if skip_arg and args:
args.pop(0) # Remove 'self' or 'cls' from the list of arguments.
Expand Down
12 changes: 8 additions & 4 deletions fire/testutils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

import sys

import six

from fire import testutils

import six


class TestTestUtils(testutils.BaseTestCase):
"""Let's get meta."""
Expand All @@ -48,8 +48,12 @@ def testCheckStdoutOrStderrNone(self):
print('blah', file=sys.stderr)

def testCorrectOrderingOfAssertRaises(self):
# Check to make sure FireExit tests are correct
# Check to make sure FireExit tests are correct.
with self.assertOutputMatches(stdout='Yep.*first.*second'):
with self.assertRaises(ValueError):
print('Yep, this is the first line.\nIt should match to the second')
print('Yep, this is the first line.\nThis is the second.')
raise ValueError()


if __name__ == '__main__':
testutils.main()

0 comments on commit d998200

Please sign in to comment.