Skip to content

Commit d998200

Browse files
committed
Fix no-else-return lint violations.
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]>
1 parent 3b04b0e commit d998200

File tree

6 files changed

+25
-28
lines changed

6 files changed

+25
-28
lines changed

doc/using-cli.md

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Using a Fire CLI
22

3-
4-
53
## Basic usage
64

75
Every Fire command corresponds to a Python component.

fire/completion.py

+8-9
Original file line numberDiff line numberDiff line change
@@ -160,18 +160,17 @@ def Completions(component, verbose=False):
160160
spec = inspectutils.GetFullArgSpec(component)
161161
return _CompletionsFromArgs(spec.args + spec.kwonlyargs)
162162

163-
elif isinstance(component, (tuple, list)):
163+
if isinstance(component, (tuple, list)):
164164
return [str(index) for index in range(len(component))]
165165

166-
elif inspect.isgenerator(component):
166+
if inspect.isgenerator(component):
167167
# TODO: There are currently no commands available for generators.
168168
return []
169169

170-
else:
171-
return [
172-
_FormatForCommand(member_name)
173-
for member_name, unused_member in _Members(component, verbose)
174-
]
170+
return [
171+
_FormatForCommand(member_name)
172+
for member_name, unused_member in _Members(component, verbose)
173+
]
175174

176175

177176
def _FormatForCommand(token):
@@ -192,8 +191,8 @@ def _FormatForCommand(token):
192191

193192
if token.startswith('_'):
194193
return token
195-
else:
196-
return token.replace('_', '-')
194+
195+
return token.replace('_', '-')
197196

198197

199198
def _Commands(component, depth=3):

fire/fire_test.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@ def testFire(self):
4444
self.assertEqual(fire.Fire(tc.OldStyleWithDefaults, 'double 2'), 4)
4545
self.assertEqual(fire.Fire(tc.OldStyleWithDefaults, 'triple 4'), 12)
4646

47-
def testFireDefaultBaseName(self):
47+
def testFireDefaultName(self):
4848
with mock.patch.object(sys, 'argv',
4949
[os.path.join('python-fire', 'fire',
5050
'base_filename.py')]):
51-
# positive case
5251
with self.assertOutputMatches(stdout='Usage: base_filename.py',
5352
stderr=None):
5453
fire.Fire(tc.Empty)

fire/helputils.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,15 @@ def UsageString(component, trace=None, verbose=False):
186186
spec = inspectutils.GetFullArgSpec(component)
187187
return _UsageStringFromFullArgSpec(command, spec)
188188

189-
elif isinstance(component, (list, tuple)):
189+
if isinstance(component, (list, tuple)):
190190
length = len(component)
191191
if length == 0:
192192
return command
193-
elif length == 1:
193+
if length == 1:
194194
return command + '[0]'
195-
else:
196-
return command + '[0..{cap}]'.format(cap=length - 1)
195+
return command + '[0..{cap}]'.format(cap=length - 1)
197196

198-
else:
199-
completions = completion.Completions(component, verbose)
200-
if command:
201-
completions = [''] + completions
202-
return '\n'.join(command + end for end in completions)
197+
completions = completion.Completions(component, verbose)
198+
if command:
199+
completions = [''] + completions
200+
return '\n'.join(command + end for end in completions)

fire/inspectutils.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,7 @@ def GetFullArgSpec(fn):
102102
# Are there other cases?
103103
if inspect.isbuiltin(fn):
104104
return FullArgSpec(varargs='vars', varkw='kwargs')
105-
else:
106-
return FullArgSpec()
105+
return FullArgSpec()
107106

108107
if skip_arg and args:
109108
args.pop(0) # Remove 'self' or 'cls' from the list of arguments.

fire/testutils_test.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020

2121
import sys
2222

23-
import six
24-
2523
from fire import testutils
2624

25+
import six
26+
2727

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

5050
def testCorrectOrderingOfAssertRaises(self):
51-
# Check to make sure FireExit tests are correct
51+
# Check to make sure FireExit tests are correct.
5252
with self.assertOutputMatches(stdout='Yep.*first.*second'):
5353
with self.assertRaises(ValueError):
54-
print('Yep, this is the first line.\nIt should match to the second')
54+
print('Yep, this is the first line.\nThis is the second.')
5555
raise ValueError()
56+
57+
58+
if __name__ == '__main__':
59+
testutils.main()

0 commit comments

Comments
 (0)