summaryrefslogtreecommitdiff
path: root/astroid
diff options
context:
space:
mode:
authorClaudiu Popa <pcmanticore@gmail.com>2016-12-18 13:32:19 +0200
committerClaudiu Popa <pcmanticore@gmail.com>2016-12-18 13:32:19 +0200
commit1fd67174a0769c467108236362ba53d98753a06c (patch)
tree2b91e62e455a3b55d2b27720a075e0e12a563445 /astroid
parent49c9dcfd103fdf28b37f686a14be755ed1ff1058 (diff)
downloadastroid-git-1fd67174a0769c467108236362ba53d98753a06c.tar.gz
Remove occurrences of no-else-return and consider-using-ternary
Diffstat (limited to 'astroid')
-rw-r--r--astroid/as_string.py36
-rw-r--r--astroid/builder.py9
-rw-r--r--astroid/context.py4
-rw-r--r--astroid/node_classes.py18
-rw-r--r--astroid/raw_building.py2
-rw-r--r--astroid/rebuilder.py4
-rw-r--r--astroid/scoped_nodes.py4
-rw-r--r--astroid/test_utils.py22
-rw-r--r--astroid/transforms.py4
9 files changed, 49 insertions, 54 deletions
diff --git a/astroid/as_string.py b/astroid/as_string.py
index 8eaebc15..962bdabb 100644
--- a/astroid/as_string.py
+++ b/astroid/as_string.py
@@ -98,10 +98,10 @@ class AsStringVisitor(object):
def visit_classdef(self, node):
"""return an astroid.ClassDef node as string"""
- decorate = node.decorators and node.decorators.accept(self) or ''
+ decorate = node.decorators.accept(self) if node.decorators else ''
bases = ', '.join([n.accept(self) for n in node.bases])
if sys.version_info[0] == 2:
- bases = bases and '(%s)' % bases or ''
+ bases = '(%s)' % bases if bases else ''
else:
metaclass = node.metaclass()
if metaclass and not node.has_metaclass_hack():
@@ -110,8 +110,8 @@ class AsStringVisitor(object):
else:
bases = '(metaclass=%s)' % metaclass.name
else:
- bases = bases and '(%s)' % bases or ''
- docs = node.doc and '\n%s"""%s"""' % (self.indent, node.doc) or ''
+ bases = '(%s)' % bases if bases else ''
+ docs = '\n%s"""%s"""' % (self.indent, node.doc) if node.doc else ''
return '\n\n%sclass %s%s:%s\n%s\n' % (decorate, node.name, bases, docs,
self._stmt_list(node.body))
@@ -232,8 +232,8 @@ class AsStringVisitor(object):
def visit_functiondef(self, node):
"""return an astroid.Function node as string"""
- decorate = node.decorators and node.decorators.accept(self) or ''
- docs = node.doc and '\n%s"""%s"""' % (self.indent, node.doc) or ''
+ decorate = node.decorators.accept(self) if node.decorators else ''
+ docs = '\n%s"""%s"""' % (self.indent, node.doc) if node.doc else ''
return_annotation = ''
if six.PY3 and node.returns:
return_annotation = '->' + node.returns.as_string()
@@ -298,7 +298,7 @@ class AsStringVisitor(object):
def visit_module(self, node):
"""return an astroid.Module node as string"""
- docs = node.doc and '"""%s"""\n\n' % node.doc or ''
+ docs = '"""%s"""\n\n' % node.doc if node.doc else ''
return docs + '\n'.join([n.accept(self) for n in node.body]) + '\n\n'
def visit_name(self, node):
@@ -335,8 +335,8 @@ class AsStringVisitor(object):
"""return an astroid.Return node as string"""
if node.value:
return 'return %s' % node.value.accept(self)
- else:
- return 'return'
+
+ return 'return'
def visit_index(self, node):
"""return a astroid.Index node as string"""
@@ -353,9 +353,9 @@ class AsStringVisitor(object):
def visit_slice(self, node):
"""return a astroid.Slice node as string"""
- lower = node.lower and node.lower.accept(self) or ''
- upper = node.upper and node.upper.accept(self) or ''
- step = node.step and node.step.accept(self) or ''
+ lower = node.lower.accept(self) if node.lower else ''
+ upper = node.upper.accept(self) if node.upper else''
+ step = node.step.accept(self) if node.step else ''
if step:
return '%s:%s:%s' % (lower, upper, step)
return '%s:%s' % (lower, upper)
@@ -409,12 +409,12 @@ class AsStringVisitor(object):
def visit_yield(self, node):
"""yield an ast.Yield node as string"""
- yi_val = node.value and (" " + node.value.accept(self)) or ""
+ yi_val = (" " + node.value.accept(self)) if node.value else ""
expr = 'yield' + yi_val
if node.parent.is_statement:
return expr
- else:
- return "(%s)" % (expr,)
+
+ return "(%s)" % (expr,)
def visit_starred(self, node):
"""return Starred node as string"""
@@ -461,12 +461,12 @@ class AsStringVisitor3(AsStringVisitor):
def visit_yieldfrom(self, node):
""" Return an astroid.YieldFrom node as string. """
- yi_val = node.value and (" " + node.value.accept(self)) or ""
+ yi_val = (" " + node.value.accept(self)) if node.value else ""
expr = 'yield from' + yi_val
if node.parent.is_statement:
return expr
- else:
- return "(%s)" % (expr,)
+
+ return "(%s)" % (expr,)
def visit_asyncfunctiondef(self, node):
function = super(AsStringVisitor3, self).visit_functiondef(node)
diff --git a/astroid/builder.py b/astroid/builder.py
index 5304aa95..ee3b7e25 100644
--- a/astroid/builder.py
+++ b/astroid/builder.py
@@ -192,7 +192,7 @@ class AstroidBuilder(raw_building.InspectBuilder):
modname = modname[:-9]
package = True
else:
- package = path and path.find('__init__.py') > -1 or False
+ package = path.find('__init__.py') > -1 if path else False
builder = rebuilder.TreeRebuilder(self._manager)
module = builder.visit_module(node, modname, node_file, package)
module._import_from_nodes = builder._import_from_nodes
@@ -411,8 +411,8 @@ def extract_node(code, module_name=''):
def _extract(node):
if isinstance(node, nodes.Expr):
return node.value
- else:
- return node
+
+ return node
requested_lines = []
for idx, line in enumerate(code.splitlines()):
@@ -434,5 +434,4 @@ def extract_node(code, module_name=''):
extracted = [_extract(node) for node in extracted]
if len(extracted) == 1:
return extracted[0]
- else:
- return extracted
+ return extracted
diff --git a/astroid/context.py b/astroid/context.py
index f693d406..627bae5d 100644
--- a/astroid/context.py
+++ b/astroid/context.py
@@ -74,5 +74,5 @@ class CallContext(object):
def copy_context(context):
if context is not None:
return context.clone()
- else:
- return InferenceContext()
+
+ return InferenceContext()
diff --git a/astroid/node_classes.py b/astroid/node_classes.py
index 7d9c1007..79d9a523 100644
--- a/astroid/node_classes.py
+++ b/astroid/node_classes.py
@@ -311,8 +311,8 @@ class NodeNG(object):
continue
if isinstance(attr, (list, tuple)):
return attr[-1]
- else:
- return attr
+
+ return attr
return None
def parent_of(self, node):
@@ -411,8 +411,8 @@ class NodeNG(object):
def fromlineno(self):
if self.lineno is None:
return self._fixed_source_line()
- else:
- return self.lineno
+
+ return self.lineno
@decorators.cachedproperty
def tolineno(self):
@@ -423,12 +423,8 @@ class NodeNG(object):
lastchild = self.last_child()
if lastchild is None:
return self.fromlineno
- else:
- return lastchild.tolineno
- # TODO / FIXME:
- assert self.fromlineno is not None, self
- assert self.tolineno is not None, self
+ return lastchild.tolineno
def _fixed_source_line(self):
"""return the line number where the given node appears
@@ -1430,8 +1426,8 @@ class ExceptHandler(mixins.AssignTypeMixin, Statement):
return self.name.tolineno
elif self.type:
return self.type.tolineno
- else:
- return self.lineno
+
+ return self.lineno
def catch(self, exceptions): # pylint: disable=redefined-outer-name
if self.type is None or exceptions is None:
diff --git a/astroid/raw_building.py b/astroid/raw_building.py
index 8fa3e706..21e60d11 100644
--- a/astroid/raw_building.py
+++ b/astroid/raw_building.py
@@ -262,7 +262,7 @@ class InspectBuilder(object):
except AttributeError:
# in jython, java modules have no __doc__ (see #109562)
node = build_module(modname)
- node.file = node.path = path and os.path.abspath(path) or path
+ node.file = node.path = os.path.abspath(path) if path else path
node.name = modname
MANAGER.cache_module(node)
node.package = hasattr(module, '__path__')
diff --git a/astroid/rebuilder.py b/astroid/rebuilder.py
index e898c16e..e903fff2 100644
--- a/astroid/rebuilder.py
+++ b/astroid/rebuilder.py
@@ -96,8 +96,8 @@ def _visit_or_none(node, attr, visitor, parent, visit='visit',
value = getattr(node, attr, None)
if value:
return getattr(visitor, visit)(value, parent, **kws)
- else:
- return None
+
+ return None
def _get_context(node):
diff --git a/astroid/scoped_nodes.py b/astroid/scoped_nodes.py
index a61e1d56..abad18aa 100644
--- a/astroid/scoped_nodes.py
+++ b/astroid/scoped_nodes.py
@@ -1140,8 +1140,8 @@ class ClassDef(mixins.FilterStmtsMixin, LocalsDictNodeNG,
def blockstart_tolineno(self):
if self.bases:
return self.bases[-1].tolineno
- else:
- return self.fromlineno
+
+ return self.fromlineno
def block_range(self, lineno):
"""return block line numbers.
diff --git a/astroid/test_utils.py b/astroid/test_utils.py
index 3bdffd79..e7e64b17 100644
--- a/astroid/test_utils.py
+++ b/astroid/test_utils.py
@@ -30,17 +30,17 @@ def require_version(minver=None, maxver=None):
current = sys.version_info[:3]
if parse(minver, "0") < current <= parse(maxver, "4"):
return f
- else:
- str_version = '.'.join(str(v) for v in sys.version_info)
- @functools.wraps(f)
- def new_f(self, *args, **kwargs):
- if minver is not None:
- self.skipTest('Needs Python > %s. Current version is %s.'
- % (minver, str_version))
- elif maxver is not None:
- self.skipTest('Needs Python <= %s. Current version is %s.'
- % (maxver, str_version))
- return new_f
+
+ str_version = '.'.join(str(v) for v in sys.version_info)
+ @functools.wraps(f)
+ def new_f(self, *args, **kwargs):
+ if minver is not None:
+ self.skipTest('Needs Python > %s. Current version is %s.'
+ % (minver, str_version))
+ elif maxver is not None:
+ self.skipTest('Needs Python <= %s. Current version is %s.'
+ % (maxver, str_version))
+ return new_f
return check_require_version
diff --git a/astroid/transforms.py b/astroid/transforms.py
index 9914ea29..852b9854 100644
--- a/astroid/transforms.py
+++ b/astroid/transforms.py
@@ -57,8 +57,8 @@ class TransformVisitor(object):
return [self._visit_generic(child) for child in node]
elif isinstance(node, tuple):
return tuple(self._visit_generic(child) for child in node)
- else:
- return self._visit(node)
+
+ return self._visit(node)
def register_transform(self, node_class, transform, predicate=None):
"""Register `transform(node)` function to be applied on the given