Simplify method by removing else branch after return.

This commit is contained in:
Bastian Kleineidam 2010-03-06 12:09:05 +01:00
parent a2fb1e578f
commit 4cee825589
1 changed files with 35 additions and 36 deletions

View File

@ -162,50 +162,49 @@ class Baker(object):
return lambda fn: self.command(fn, default=default, return lambda fn: self.command(fn, default=default,
params=params, params=params,
shortopts=shortopts) shortopts=shortopts)
else: name = name or fn.__name__
name = name or fn.__name__
# Inspect the argument signature of the function # Inspect the argument signature of the function
arglist, vargsname, kwargsname, defaults = getargspec(fn) arglist, vargsname, kwargsname, defaults = getargspec(fn)
has_varargs = bool(vargsname) has_varargs = bool(vargsname)
has_kwargs = bool(kwargsname) has_kwargs = bool(kwargsname)
# Get the function's docstring # Get the function's docstring
docstring = fn.__doc__ or "" docstring = fn.__doc__ or ""
# If the user didn't specify parameter help in the decorator # If the user didn't specify parameter help in the decorator
# arguments, try to get it from parameter annotations (Python 3.x) # arguments, try to get it from parameter annotations (Python 3.x)
# or RST-style :param: lines in the docstring # or RST-style :param: lines in the docstring
if params is None: if params is None:
if hasattr(fn, "func_annotations") and fn.func_annotations: if hasattr(fn, "func_annotations") and fn.func_annotations:
params = fn.func_annotations params = fn.func_annotations
else:
params = find_param_docs(docstring)
docstring = remove_param_docs(docstring)
# If the user didn't specify
shortopts = shortopts or {}
# Zip up the keyword argument names with their defaults
if defaults:
keywords = dict(zip(arglist[0-len(defaults):], defaults))
else: else:
keywords = {} params = find_param_docs(docstring)
docstring = remove_param_docs(docstring)
# If this is a method, remove 'self' from the argument list # If the user didn't specify
if arglist and arglist[0] == "self": shortopts = shortopts or {}
arglist.pop(0)
# Create a Cmd object to represent this command and store it # Zip up the keyword argument names with their defaults
cmd = Cmd(name, fn, arglist, keywords, shortopts, if defaults:
has_varargs, has_kwargs, keywords = dict(zip(arglist[0-len(defaults):], defaults))
docstring, params) else:
self.commands[cmd.name] = cmd keywords = {}
# If default is True, set this as the default command # If this is a method, remove 'self' from the argument list
if default: self.defaultcommand = cmd if arglist and arglist[0] == "self":
arglist.pop(0)
return fn # Create a Cmd object to represent this command and store it
cmd = Cmd(name, fn, arglist, keywords, shortopts,
has_varargs, has_kwargs,
docstring, params)
self.commands[cmd.name] = cmd
# If default is True, set this as the default command
if default: self.defaultcommand = cmd
return fn
def print_top_help(self, scriptname, file=sys.stdout): def print_top_help(self, scriptname, file=sys.stdout):
"""Prints the documentation for the script and exits. """Prints the documentation for the script and exits.