Compare commits
1 Commits
main
...
0d5ba8b921
| Author | SHA1 | Date | |
|---|---|---|---|
| 0d5ba8b921 |
@@ -0,0 +1,26 @@
|
|||||||
|
"""
|
||||||
|
Module implementing message related functions and classes.
|
||||||
|
"""
|
||||||
|
from typing import Type, TypeVar
|
||||||
|
|
||||||
|
QuestionInst = TypeVar('QuestionInst', bound='Question')
|
||||||
|
|
||||||
|
|
||||||
|
class MessageError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class Question(str):
|
||||||
|
"""
|
||||||
|
A single question with a defined prefix.
|
||||||
|
"""
|
||||||
|
prefix = '=== QUESTION ==='
|
||||||
|
|
||||||
|
def __new__(cls: Type[QuestionInst], string: str) -> QuestionInst:
|
||||||
|
"""
|
||||||
|
Make sure the tag string does not contain the default separator.
|
||||||
|
"""
|
||||||
|
if cls.prefix in string:
|
||||||
|
raise MessageError(f"Question '{string}' contains the prefix '{cls.prefix}'")
|
||||||
|
instance = super().__new__(cls, string)
|
||||||
|
return instance
|
||||||
Reference in New Issue
Block a user