Kaydet (Commit) a40ff6df authored tarafından Berker Peksag's avatar Berker Peksag

More cleanup and use modern Python idioms.

üst b31b9769
...@@ -144,7 +144,7 @@ class ExplicitNodeVisitor(ast.NodeVisitor): ...@@ -144,7 +144,7 @@ class ExplicitNodeVisitor(ast.NodeVisitor):
""" """
def abort_visit(node): def abort_visit(node): # XXX: self?
msg = 'No defined handler for node of type %s' msg = 'No defined handler for node of type %s'
raise AttributeError(msg % node.__class__.__name__) raise AttributeError(msg % node.__class__.__name__)
...@@ -156,9 +156,8 @@ class ExplicitNodeVisitor(ast.NodeVisitor): ...@@ -156,9 +156,8 @@ class ExplicitNodeVisitor(ast.NodeVisitor):
def parsefile(fname): def parsefile(fname):
f = open(fname, 'r') with open(fname, 'r') as f:
fstr = f.read() fstr = f.read()
f.close()
fstr = fstr.replace('\r\n', '\n').replace('\r', '\n') fstr = fstr.replace('\r\n', '\n').replace('\r', '\n')
if not fstr.endswith('\n'): if not fstr.endswith('\n'):
fstr += '\n' fstr += '\n'
...@@ -172,8 +171,8 @@ class CodeToAst(object): ...@@ -172,8 +171,8 @@ class CodeToAst(object):
number of compiles. number of compiles.
""" """
def __init__(self, cache): def __init__(self, cache=None):
self.cache = cache self.cache = cache or {}
def __call__(self, codeobj): def __call__(self, codeobj):
cache = self.cache cache = self.cache
...@@ -195,4 +194,4 @@ class CodeToAst(object): ...@@ -195,4 +194,4 @@ class CodeToAst(object):
cache[(fname, obj.lineno)] = obj cache[(fname, obj.lineno)] = obj
return cache[key] return cache[key]
codetoast = CodeToAst({}) codetoast = CodeToAst()
...@@ -57,7 +57,7 @@ class TreeWalk(MetaFlatten): ...@@ -57,7 +57,7 @@ class TreeWalk(MetaFlatten):
""" """
nodestack = None nodestack = None
def __init__(self, node=None, name=''): def __init__(self, node=None):
self.setup() self.setup()
if node is not None: if node is not None:
self.walk(node) self.walk(node)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment