def get_defining_item(self, code): filename = runtime.get_code_filename(code) lineno = runtime.get_code_lineno(code) modname, mod = self.find_module(code) classes = inspect.getmembers(mod, predicate=inspect.isclass) for _, clazz in inspect.getmembers(mod, predicate=inspect.isclass): for _, member in inspect.getmembers( clazz, predicate=inspect.isfunction) + inspect.getmembers( clazz, predicate=inspect.ismethod): member_code = runtime.get_code(member) member_filename = runtime.get_code_filename(member_code) member_lineno = runtime.get_code_lineno(member_code) if filename == member_filename and lineno == member_lineno: self.add_import(modname, clazz.__name__) return clazz, member for _, member in inspect.getmembers( clazz, predicate=lambda member: isinstance(member, property)): self.add_import(modname, clazz.__name__) return clazz, member for _, member in inspect.getmembers(mod, predicate=inspect.isfunction): # Module-level function support, note the difference in return statement member_code = runtime.get_code(member) member_filename = runtime.get_code_filename(member_code) member_lineno = runtime.get_code_lineno(member_code) if filename == member_filename and lineno == member_lineno: self.add_import(modname, clazz.__name__) return mod, member if modname != '__main__': self.add_import(modname) return mod, mod
def get_defining_item(self, code): filename = runtime.get_code_filename(code) lineno = runtime.get_code_lineno(code) modname, mod = self.find_module(code) print(filename, lineno, modname, mod) for _, clazz in inspect.getmembers(mod, predicate=inspect.isclass): print(clazz) for _, member in inspect.getmembers(clazz, predicate=inspect.ismethod): member_code = runtime.get_code(member) member_filename = runtime.get_code_filename(member_code) member_lineno = runtime.get_code_lineno(member_code) print(indent(1), member_filename, member_lineno) if filename == member_filename and lineno == member_lineno: self.add_import(modname, clazz.__name__) return clazz, member for _, member in inspect.getmembers( clazz, predicate=lambda member: isinstance(member, property)): self.add_import(modname, clazz.__name__) print(indent(4), member_filename, member_lineno) return clazz, member for _, member in inspect.getmembers(clazz, predicate=inspect.isfunction): member_code = runtime.get_code(member) member_filename = runtime.get_code_filename(member_code) member_lineno = runtime.get_code_lineno(member_code) print(indent(2), member_filename, member_lineno) if filename == member_filename and lineno == member_lineno: self.add_import(modname, clazz.__name__) return clazz, member # TODO this is most likely not correct or not necessary for _, member in inspect.getmembers(mod, predicate=inspect.isfunction): # Module-level function support, note the difference in return statement member_code = runtime.get_code(member) member_filename = runtime.get_code_filename(member_code) member_lineno = runtime.get_code_lineno(member_code) print(indent(3), member_filename, member_lineno) if filename == member_filename and lineno == member_lineno: self.add_import(modname, member.__name__) return mod, member if modname != '__main__': self.add_import(modname) return mod, mod
def get_defining_item(self, code): filename = runtime.get_code_filename(code) lineno = runtime.get_code_lineno(code) modname, mod = self.find_module(code) for _,clazz in inspect.getmembers(mod, predicate=inspect.isclass): if PYTHON3: if clazz.__name__.find("(") == -1: if clazz.__name__ in self.class_params and not clazz.__name__.endswith(self.class_params[clazz.__name__]): clazz.__name__ = clazz.__name__+self.class_params[clazz.__name__] elif not clazz.__name__.endswith("()"): clazz.__name__ = clazz.__name__+"()" for _,member in inspect.getmembers(clazz, predicate=inspect.ismethod): member_code = runtime.get_code(member) member_filename = runtime.get_code_filename(member_code) member_lineno = runtime.get_code_lineno(member_code) if filename == member_filename and lineno == member_lineno: self.add_import(modname, clazz.__name__) return clazz, member for _,member in inspect.getmembers(clazz, predicate=lambda member: isinstance(member, property)): self.add_import(modname, clazz.__name__) return clazz, member for _,member in inspect.getmembers(clazz, predicate=inspect.isfunction): member_code = runtime.get_code(member) member_filename = runtime.get_code_filename(member_code) member_lineno = runtime.get_code_lineno(member_code) if filename == member_filename and lineno == member_lineno: self.add_import(modname, clazz.__name__) return clazz, member for _,member in inspect.getmembers(mod, predicate=inspect.isfunction): # Module-level function support, note the difference in return statement member_code = runtime.get_code(member) member_filename = runtime.get_code_filename(member_code) member_lineno = runtime.get_code_lineno(member_code) if filename == member_filename and lineno == member_lineno: self.add_import(modname, clazz.__name__) return mod, member if modname != '__main__': self.add_import(modname) return mod, mod