Coverage for src / mesh / models / roles / visitor.py: 93%

14 statements  

« prev     ^ index     » next       coverage.py v7.13.1, created at 2026-05-04 12:41 +0000

1from abc import ABC, abstractmethod 

2from typing import TYPE_CHECKING, Generic, TypeVar 

3 

4if TYPE_CHECKING: 

5 from mesh.models.roles.base_role import Role 

6 

7VisitorRT = TypeVar("VisitorRT") 

8 

9 

10class RoleVisitor(ABC, Generic[VisitorRT]): 

11 role: "Role" 

12 

13 def __init__(self, role: "Role", *args, **kwargs): 

14 self.role = role 

15 super().__init__(*args, **kwargs) 

16 

17 def visit(self, *args, **kwargs) -> VisitorRT: 

18 function_name = f"visit_{self.role.code()}" 

19 ftor = getattr(self, function_name, None) 

20 if not callable(ftor): 

21 raise LookupError(f"RoleVisitor does not implements {function_name}") 

22 return ftor(*args, **kwargs) # type:ignore 

23 

24 @abstractmethod 

25 def visit_author(self, *args, **kwargs) -> VisitorRT: ... 

26 

27 @abstractmethod 

28 def visit_editor(self, *args, **kwargs) -> VisitorRT: ... 

29 

30 @abstractmethod 

31 def visit_journal_manager(self, *args, **kwargs) -> VisitorRT: ... 

32 

33 @abstractmethod 

34 def visit_reviewer(self, *args, **kwargs) -> VisitorRT: ...