The new class uses Vitalije's suggested patterns.  This @button node tests 
the code:

import imp
import leo.core.leoCheck as leoCheck
imp.reload(leoCheck)
files = leoCheck.ProjectUtils().leo_core_files()
leoCheck.NewShowData().run(files[:2])

Here are the good parts:

def analyze(self, fn, root):

    table = (
        (self.assigns_d, (ast.Assign, ast.AugAssign)),
        (self.calls_d, ast.Call),
        (self.classes_d, ast.ClassDef),
        (self.defs_d, ast.FunctionDef),
        (self.returns_d, ast.Return),
    )
    self.fn = fn = g.shortFileName(fn)
    for d, ast_types in table:
        d[fn] = []
    for node in ast.walk(root):
        for d, types in table:
            d[fn].extend(self.visit(node, types))

def format(self, node):
    
    class Formatter(leoAst.AstFormatter):
        level = 0
    
    s = Formatter().visit(node)
    line1 = g.splitLines(s)[0].strip()
    return g.truncate(line1, 80)

def show_results(self):
    '''Print a summary of the test results.'''
    table = (
        ('assignments', self.assigns_d),
        ('calls', self.calls_d),
        ('classes', self.classes_d),
        ('defs', self.defs_d),
        ('returns', self.returns_d),
    )
    for (name, d) in table:
        print('%s...' % name)
        d2 = {}
        for key in d:
            d2[key] = sorted(set(d.get(key)))
        g.printDict(d2)

def visit(self, node, types):
    if isinstance(node, types):
        yield self.format(node)

And that's it.  Quite a contrast from the old ShowData and 
ShowDataTraverser classes.

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to