Attachment 'list_parents.sage'

Download

   1 import sys, types
   2 
   3 bad_methods = ['_coerce_impl', '_coerce_']
   4 
   5 def needs_work(obj):
   6     if isinstance(obj.__call__, types.MethodType):
   7         inherit_call = False
   8         for b in obj.__bases__:
   9             try:
  10                 if obj.__call__ == b.__call__:
  11                     inherit_call = True
  12             except AttributeError, msg:
  13                 pass
  14         if not inherit_call:
  15             return True
  16             
  17     elif obj.__call__.__objclass__ == obj:
  18         return True
  19         
  20     for m in bad_methods:
  21         if hasattr(obj, m):
  22             return True
  23             
  24 
  25 def list_descendants(m, t, recurse=True):
  26     print m.__name__
  27     
  28 #    print "  Named instances: "
  29 #    for name, obj in m.__dict__.items():
  30 #        if isinstance(obj, t):
  31 #            print "    ", name
  32 #    print "  Named Classes: "
  33 
  34     for name, obj in m.__dict__.items():
  35         if isinstance(obj, type):
  36             if t in obj.mro():
  37                 if obj is sage.structure.parent.Parent:
  38                     continue
  39                 if needs_work(obj):
  40                     star = '*'
  41                 else:
  42                     star = ' '
  43                 if obj.__module__ != m.__name__:
  44                     print "   %s (%s.%s)" % (star, obj.__module__, name)
  45                 else:
  46                     print "   %s %s" % (star, name)
  47 
  48     if recurse:
  49         for name, obj in m.__dict__.items():
  50             if isinstance(obj, types.ModuleType) \
  51                     and m.__name__ != obj.__name__ \
  52                     and m.__name__ in obj.__name__:
  53                 list_descendants(obj, t, True)
  54 
  55 
  56 if len(sys.argv) < 2:
  57     print """
  58 Usage: 
  59   sage list_parents.sage 'sage.dotted.module'
  60     """
  61 
  62 for modstr in sys.argv[1:]:
  63     m = __import__(modstr, fromlist=['*'])
  64     list_descendants(m, Parent)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2008-02-22 08:02:17, 9.1 KB) [[attachment:coerce-free-module.patch]]
  • [get | view] (2008-06-14 07:28:06, 1.1 KB) [[attachment:fix-random.patch]]
  • [get | view] (2008-04-16 03:14:59, 1.8 KB) [[attachment:list_parents.sage]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.