def visit_Module(self, node: ast.Module) -> None: assert self.module.docstring is None self.builder.push(self.module, 0) if len(node.body) > 0 and isinstance(node.body[0], ast.Expr) and isinstance(node.body[0].value, ast.Str): self.module.setDocstring(node.body[0].value) epydoc2stan.extract_fields(self.module) self.default(node) self.builder.pop(self.module)
def push(self, obj): self._stack.append(self.current) self.current = obj if isinstance(obj, model.Module): assert self.currentMod is None obj.parentMod = self.currentMod = obj elif self.currentMod is not None: if obj.parentMod is not None: assert obj.parentMod is self.currentMod else: obj.parentMod = self.currentMod else: assert obj.parentMod is None if not isinstance(obj, model.Function): epydoc2stan.extract_fields(obj)
def push(self, obj): self._stack.append(self.current) self.current = obj if isinstance(obj, model.Module): assert self.currentMod is None obj.parentMod = self.currentMod = obj elif self.currentMod is not None: if obj.parentMod is not None: assert obj.parentMod is self.currentMod else: obj.parentMod = self.currentMod else: assert obj.parentMod is None # Method-level import to avoid a circular dependency. from pydoctor import epydoc2stan for attrobj in epydoc2stan.extract_fields(obj): self.system.addObject(attrobj)
def push(self, obj): self._stack.append(self.current) self.current = obj if isinstance(obj, model.Module): assert self.currentMod is None obj.parentMod = self.currentMod = obj elif self.currentMod is not None: if obj.parentMod is not None: assert obj.parentMod is self.currentMod else: obj.parentMod = self.currentMod else: assert obj.parentMod is None # Method-level import to avoid a circular dependency. from pydoctor import epydoc2stan for attrobj in epydoc2stan.extract_fields(obj): self.system.addObject(attrobj)
def visit_ClassDef(self, node): # Ignore classes within functions. parent = self.builder.current if isinstance(parent, model.Function): return None rawbases = [] bases = [] baseobjects = [] for n in node.bases: if isinstance(n, ast.Name): str_base = n.id else: str_base = astor.to_source(n).strip() rawbases.append(str_base) full_name = parent.expandName(str_base) bases.append(full_name) baseobj = self.system.objForFullName(full_name) if not isinstance(baseobj, model.Class): baseobj = None baseobjects.append(baseobj) lineno = node.lineno if node.decorator_list: lineno = node.decorator_list[0].lineno cls = self.builder.pushClass(node.name, lineno) cls.decorators = [] cls.rawbases = rawbases cls.bases = bases cls.baseobjects = baseobjects if len(node.body) > 0 and isinstance(node.body[0], ast.Expr) and isinstance( node.body[0].value, ast.Str): cls.setDocstring(node.body[0].value) epydoc2stan.extract_fields(cls) if node.decorator_list: for decnode in node.decorator_list: if isinstance(decnode, ast.Call): args = [] for arg in decnode.args: args.append(node2fullname(arg, parent)) base = node2fullname(decnode.func, parent) else: base = node2fullname(decnode, parent) args = None if base is None: # pragma: no cover # There are expressions for which node2data() returns None, # but I cannot find any that don't lead to a SyntaxError # when used in a decorator. cls.report("cannot make sense of class decorator") else: cls.decorators.append((base, args)) cls.raw_decorators = node.decorator_list if node.decorator_list else [] for b in cls.baseobjects: if b is not None: b.subclasses.append(cls) self.default(node) self.builder.popClass() return cls
def visit_ClassDef(self, node): # Ignore classes within functions. parent = self.builder.current if isinstance(parent, model.Function): return rawbases = [] bases = [] baseobjects = [] for n in node.bases: if isinstance(n, ast.Name): str_base = n.id else: str_base = astor.to_source(n).strip() rawbases.append(str_base) full_name = parent.expandName(str_base) bases.append(full_name) baseobj = self.system.objForFullName(full_name) if not isinstance(baseobj, model.Class): baseobj = None baseobjects.append(baseobj) lineno = node.lineno if node.decorator_list: lineno = node.decorator_list[0].lineno cls = self.builder.pushClass(node.name, lineno) cls.decorators = [] cls.rawbases = rawbases cls.bases = bases cls.baseobjects = baseobjects if len(node.body) > 0 and isinstance(node.body[0], ast.Expr) and isinstance( node.body[0].value, ast.Str): cls.setDocstring(node.body[0].value) epydoc2stan.extract_fields(cls) def node2data(node): dotted_name = node2dottedname(node) if dotted_name is None: return None dotted_name = '.'.join(dotted_name) full_name = self.builder.current.expandName(dotted_name) obj = self.system.objForFullName(full_name) return (dotted_name, full_name, obj) if node.decorator_list: for decnode in node.decorator_list: if isinstance(decnode, ast.Call): args = [] for arg in decnode.args: args.append(node2data(arg)) base = node2data(decnode.func) else: base = node2data(decnode) args = None cls.decorators.append((base, args)) cls.raw_decorators = node.decorator_list if node.decorator_list else [] for b in cls.baseobjects: if b is not None: b.subclasses.append(cls) self.default(node) self.builder.popClass()