Перейти к содержанию

Модели

Модуль

module

PythonModule

PythonModule(file_path: Path)
Source code in docstr_health/models/module.py
13
14
15
16
17
18
def __init__(self, file_path: Path):
    self.file_path = file_path
    self._tree: ast.Module | None = None
    self._functions: list[PythonFunction] | None = None
    self._functions_to_check: list[PythonFunction] | None = None
    self._module_docstring = _UNSET

file_path instance-attribute

file_path = file_path

tree property

tree: Module | None

Lazy loading ast-tree

functions property

functions: list[PythonFunction]

functions_to_check property

functions_to_check: list[PythonFunction]

release_tree

release_tree()
Source code in docstr_health/models/module.py
35
36
37
38
def release_tree(self):
    self._tree = None
    self._functions = None
    self._functions_to_check = None

get_module_docstring

get_module_docstring() -> str | object | None
Source code in docstr_health/models/module.py
72
73
74
75
def get_module_docstring(self) -> str | object | None:
    if self._module_docstring is _UNSET:
        self._module_docstring = ast.get_docstring(self.tree) if self.tree else None
    return self._module_docstring

get_functions_size

get_functions_size() -> dict[str, int]
Source code in docstr_health/models/module.py
77
78
def get_functions_size(self) -> dict[str, int]:
    return {func.name: func.size for func in self.functions}

Функция

function

PythonFunction

PythonFunction(name: str, ast_node, source_file=None)
Source code in docstr_health/models/function.py
 5
 6
 7
 8
 9
10
11
12
def __init__(self, name: str, ast_node, source_file=None):
    self._source_file = source_file
    self.node_type: str = type(ast_node).__name__
    self.name: str = self._set_name(name)
    self.lineno: int = ast_node.lineno
    self.end_lineno: int | None = ast_node.end_lineno
    self._docstring: str | None = ast.get_docstring(ast_node)
    self._decorator_names: list[str] = self._extract_decorators(ast_node)

node_type instance-attribute

node_type: str = type(ast_node).__name__

name instance-attribute

name: str = self._set_name(name)

lineno instance-attribute

lineno: int = ast_node.lineno

end_lineno instance-attribute

end_lineno: int | None = ast_node.end_lineno

is_full_dunder property

is_full_dunder: bool

is_once_dunder property

is_once_dunder: bool

size property

size: int

has_docstring property

has_docstring: bool

get_docstring

get_docstring() -> str | None
Source code in docstr_health/models/function.py
55
56
def get_docstring(self) -> str | None:
    return self._docstring

is_decorator_applied

is_decorator_applied(decorator_name: str) -> bool
Source code in docstr_health/models/function.py
58
59
def is_decorator_applied(self, decorator_name: str) -> bool:
    return decorator_name in self._decorator_names

Класс

class

PythonClass

PythonClass(name: str, ast_node: ClassDef)
Source code in docstr_health/models/class.py
5
def __init__(self, name: str, ast_node: ast.ClassDef): ...

Отчёт

report

ModuleReport

ModuleReport(
    module_status: str,
    inspected_functions: list[PythonFunction],
)
Source code in docstr_health/models/report.py
 7
 8
 9
10
11
12
def __init__(
    self, module_status: str, inspected_functions: list[PythonFunction]
) -> None:
    self.module_status: str = module_status
    self._func_names: list[str] = [f.name for f in inspected_functions]
    self._func_types: dict[str, int] = self._count_types(inspected_functions)

module_status instance-attribute

module_status: str = module_status

inspected_functions property

inspected_functions

get_func_type_quantity

get_func_type_quantity() -> dict
Source code in docstr_health/models/report.py
30
31
def get_func_type_quantity(self) -> dict:
    return self._func_types

ProjectReport

ProjectReport(statuses: Counter | None = None)
Source code in docstr_health/models/report.py
35
36
def __init__(self, statuses: Counter | None = None) -> None:
    self._statuses = statuses

get_project_status

get_project_status() -> str
Source code in docstr_health/models/report.py
38
39
40
41
42
def get_project_status(self) -> str:
    if self._statuses:
        return self._statuses.most_common(1)[0][0]
    else:
        raise ValueError