Skip to content

Commit

Permalink
Flake8 compat
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-sans-paille committed Sep 12, 2019
1 parent ff05b4f commit 8f8f312
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 11 deletions.
29 changes: 19 additions & 10 deletions beniget/beniget.py
@@ -1,6 +1,5 @@
from collections import defaultdict, OrderedDict
from contextlib import contextmanager
from copy import deepcopy
import sys

import gast as ast
Expand Down Expand Up @@ -75,7 +74,8 @@ def parentInstance(self, node, cls):
raise ValueError("{} has no parent of type {}".format(node, cls))

def parentFunction(self, node):
return self.parentInstance(node, (ast.FunctionDef, ast.AsyncFunctionDef))
return self.parentInstance(node, (ast.FunctionDef,
ast.AsyncFunctionDef))

def parentStmt(self, node):
return self.parentInstance(node, ast.stmt)
Expand All @@ -101,7 +101,9 @@ def name(self):
If the node associated to this Def has a name, returns this name.
Otherwise returns its type
"""
if isinstance(self.node, (ast.ClassDef, ast.FunctionDef, ast.AsyncFunctionDef)):
if isinstance(self.node, (ast.ClassDef,
ast.FunctionDef,
ast.AsyncFunctionDef)):
return self.node.name
elif isinstance(self.node, ast.Name):
return self.node.id
Expand All @@ -128,7 +130,8 @@ def _repr(self, nodes):
else:
nodes[self] = len(nodes)
return "{} -> ({})".format(
self.node, ", ".join(u._repr(nodes.copy()) for u in self._users)
self.node, ", ".join(u._repr(nodes.copy())
for u in self._users)
)

def __str__(self):
Expand All @@ -140,7 +143,8 @@ def _str(self, nodes):
else:
nodes[self] = len(nodes)
return "{} -> ({})".format(
self.name(), ", ".join(u._str(nodes.copy()) for u in self._users)
self.name(), ", ".join(u._str(nodes.copy())
for u in self._users)
)


Expand Down Expand Up @@ -210,7 +214,7 @@ def __init__(self):
# be defined in another path of the control flow (esp. in loop)
self._undefs = []

# stack of current node holding definitions (class, module, function...)
# stack of current node holding definitions: class, module, function...
self._currenthead = []

# dead code levels
Expand All @@ -221,7 +225,8 @@ def __init__(self):
def dump_definitions(self, node, ignore_builtins=True):
if isinstance(node, ast.Module) and not ignore_builtins:
builtins = {d for d in self._builtins.values()}
return sorted(d.name() for d in self.locals[node] if d not in builtins)
return sorted(d.name()
for d in self.locals[node] if d not in builtins)
else:
return sorted(d.name() for d in self.locals[node])

Expand Down Expand Up @@ -335,7 +340,8 @@ def visit_Module(self, node):

# handle function bodies
for fnode, ctx in self._defered[-1]:
visitor = getattr(self, "visit_{}".format(type(fnode).__name__))
visitor = getattr(self,
"visit_{}".format(type(fnode).__name__))
defs, self._definitions = self._definitions, ctx
visitor(fnode, step=DefinitionStep)
self._definitions = defs
Expand Down Expand Up @@ -428,7 +434,8 @@ def visit_Delete(self, node):
self.visit(target)

def visit_Assign(self, node):
dvalue = self.visit(node.value)
# link is implicit through ctx
self.visit(node.value)
for target in node.targets:
self.visit(target)

Expand Down Expand Up @@ -961,7 +968,9 @@ def unbound_identifier(self, name, node):
else:
location = ""
print(
"W: unbound identifier '{}'{}{}".format(name, location, self.filename)
"W: unbound identifier '{}'{}{}".format(name,
location,
self.filename)
)

class Beniget(ast.NodeVisitor):
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Expand Up @@ -15,7 +15,8 @@
long_description="""
A static analyzer for Python2 and Python3 code.
Beniget provides a static over-approximation of the global and local definitions inside Python Module/Class/Function.
Beniget provides a static over-approximation of the global and
local definitions inside Python Module/Class/Function.
It can also compute def-use chains from each definition.""",
author="serge-sans-paille",
author_email="serge.guelton@telecom-bretagne.eu",
Expand Down

0 comments on commit 8f8f312

Please sign in to comment.