Ticket #11108: trac_11108-review.patch

File trac_11108-review.patch, 2.0 KB (added by ncohen, 11 years ago)
  • sage/misc/classgraph.py

    # HG changeset patch
    # User Nathann Cohen <nathann.cohen@gmail.com>
    # Date 1301906054 -7200
    # Node ID 5c88a4808d6ca3cea205cfe656e1ded3421e9e75
    # Parent  675bd6a9bc35fadae49b50624eb30978fe05fdce
    trac 11108 - improve classgraph (3-lines comment in the code)
    
    diff -r 675bd6a9bc35 -r 5c88a4808d6c sage/misc/classgraph.py
    a b  
    6969        sage: G = class_graph(sage.rings.polynomial.padics, depth=2); G
    7070        Digraph on 4 vertices
    7171    """
    72     # termination
     72    # This function is recursive and uses a "global" dictionary
     73    # "classes" which associated to each class the list of its
     74    # children.
     75
     76    # The list "children" (the children of "top") is set to be the
     77    # value of children[top]. In turn, class_graph is called on all
     78    # the children which will modify the entries in "classes"
     79
     80
     81    # Termination
    7382    if depth < 0:
    7483        return classes
    7584
     85    # (first recursive call)
    7686    if classes is None:
    7787        classes = dict()
    7888
     
    8191            return classes
    8292        if name_filter is None:
    8393            name_filter = top.__name__
    84         childs = [item for item in top.__dict__.values()
     94        children = [item for item in top.__dict__.values()
    8595                       if inspect.ismodule(item) or inspect.isclass(item)]
    8696        depth = depth -1
    8797    elif inspect.isclass(top):
     
    8999            name_filter = ""
    90100        if not top.__module__.startswith(name_filter):
    91101            return classes
    92         childs = top.__bases__
    93         classes[top.__name__] = [e.__name__ for e in childs]
     102        children = top.__bases__
     103        classes[top.__name__] = [e.__name__ for e in children]
    94104    else: # top is a plain Python object; inspect its class
    95         childs = [top.__class__]
     105        children = [top.__class__]
    96106
    97     for child in childs:
     107    for child in children:
    98108        class_graph(child, depth = depth, name_filter=name_filter, classes=classes, as_graph = False)
    99109
    100110    if as_graph: