Пример #1
0
 def module(self, mod_name):
     __import__(mod_name)
     with self.fmt.module(mod_name):
         module = sys.modules[mod_name]
         members = inspect.getmembers(module, inspect.isclass)
         ret = self.result_type()
         for class_name, klass in members:
             ret.update(self.klass(class_name, klass))
         return ret
Пример #2
0
def enum_module(mod_name):
    __import__(mod_name)
    count = 0
    module = sys.modules[mod_name]
    dprint()
    dprint("Module", mod_name)
    members = inspect.getmembers(module, inspect.isclass)
    for class_name, klass in members:
        signature = getattr(klass, '__signature__', None)
        dprint()
        # class_members = inspect.getmembers(klass)
        # gives us also the inherited things.
        dprint("  class {}:".format(class_name))
        if signature is None:
            pass  # initialization not called?
        elif isinstance(signature, list):
            dprint("    with overloading():")
            for overload in signature:
                dprint("      def __init__" + str(overload))
        else:
            dprint("    def __init__" + str(signature))
        count += 1
        have_sig = signature is not None
        have_members = 0
        class_members = sorted(list(klass.__dict__.items()))
        for func_name, func in class_members:
            signature = getattr(func, '__signature__', None)
            if signature is not None:
                if isinstance(signature, list):
                    dprint("    with overloading():")
                    for overload in signature:
                        dprint("      def", func_name + str(overload))
                else:
                    dprint("    def", func_name + str(signature))
                count += 1
                have_members = count
        if not have_sig and not have_members:
            # print at least "pass"
            dprint("    pass")
    return count