added 'message_in()' function and test

This commit is contained in:
2023-08-31 09:19:38 +02:00
committed by Oleksandr Kozachuk
parent 74c39070d6
commit dc3f3dc168
2 changed files with 30 additions and 2 deletions
+15 -1
View File
@@ -3,7 +3,7 @@ Module implementing message related functions and classes.
"""
import pathlib
import yaml
from typing import Type, TypeVar, ClassVar, Optional, Any, Union, Final, Literal
from typing import Type, TypeVar, ClassVar, Optional, Any, Union, Final, Literal, Iterable
from dataclasses import dataclass, asdict, field
from .tags import Tag, TagLine, TagError, match_tags
@@ -57,6 +57,20 @@ def source_code(text: str, include_delims: bool = False) -> list[str]:
return code_sections
def message_in(message: MessageInst, messages: Iterable[MessageInst]) -> bool:
"""
Searches the given message list for a message with the same file
name as the given one (i. e. it compares Message.file_path.name).
If the given message has no file_path, False is returned.
"""
if not message.file_path:
return False
for m in messages:
if m.file_path and m.file_path.name == message.file_path.name:
return True
return False
@dataclass(kw_only=True)
class MessageFilter:
"""