def _declared_at(self) -> dict[str, tuple[str, str]]: declared_at: dict[str, tuple[str, str]] = {} for cls in self.obj.__mro__: treeinfo = doc_ast.walk_tree(cls) for name in treeinfo.docstrings.keys() | treeinfo.annotations.keys(): declared_at.setdefault( name, (cls.__module__, f"{cls.__qualname__}.{name}") ) for name in cls.__dict__: declared_at.setdefault( name, (cls.__module__, f"{cls.__qualname__}.{name}") ) return declared_at
def _var_annotations(self) -> dict[str, type]: annotations: dict[str, type] = {} for cls in self.obj.__mro__: cls_annotations = doc_ast.walk_tree(cls).annotations.copy() dynamic_annotations = _safe_getattr(cls, "__annotations__", None) if isinstance(dynamic_annotations, dict): for k, v in dynamic_annotations.items(): cls_annotations[k] = v cls_fullname = (_safe_getattr(cls, "__module__", "") + "." + cls.__qualname__).lstrip(".") cls_annotations = resolve_annotations(cls_annotations, inspect.getmodule(cls), cls_fullname) for k, v in cls_annotations.items(): annotations.setdefault(k, v) return annotations
def _declarations(self) -> dict[str, tuple[str, str]]: decls: dict[str, tuple[str, str]] = {} for cls in self.obj.__mro__: treeinfo = doc_ast.walk_tree(cls) for name in treeinfo.docstrings.keys() | treeinfo.annotations.keys( ): decls.setdefault( name, (cls.__module__, f"{cls.__qualname__}.{name}")) for name in cls.__dict__: decls.setdefault( name, (cls.__module__, f"{cls.__qualname__}.{name}")) if decls.get("__init__", None) == ("builtins", "object.__init__"): decls["__init__"] = ( self.obj.__module__, f"{self.obj.__qualname__}.__init__", ) return decls
def _var_docstrings(self) -> dict[str, str]: docstrings: dict[str, str] = {} for cls in self.obj.__mro__: for name, docstr in doc_ast.walk_tree(cls).docstrings.items(): docstrings.setdefault(name, docstr) return docstrings
def _var_annotations(self) -> dict[str, Any]: annotations = doc_ast.walk_tree(self.obj).annotations.copy() for k, v in _safe_getattr(self.obj, "__annotations__", {}).items(): annotations[k] = v return resolve_annotations(annotations, self.obj, self.fullname)
def _var_docstrings(self) -> dict[str, str]: return doc_ast.walk_tree(self.obj).docstrings