4
1
Fork 1

Update validate static function

This commit is contained in:
trueold89 2024-08-03 13:49:08 +03:00
parent 6e4959e918
commit e8acbd89c7
Signed by: trueold89
GPG Key ID: C122E85DD49E6B30
1 changed files with 5 additions and 3 deletions

View File

@ -8,12 +8,14 @@
from tubot.static.abc import IValidatable from tubot.static.abc import IValidatable
async def validate(obj: IValidatable) -> bool: async def validate(obj: IValidatable, msg: str | None = None) -> bool:
""" """
Checks the validity of the object Throws an exception if the object has not been validated
:return: Object validity boolean :return: Object validity boolean
""" """
if await obj.__validate__(): if await obj.__validate__():
return True return True
if msg is None:
raise TypeError("Object validation failed") raise TypeError("Object validation failed")
raise TypeError(f"Object validation failed: {msg}")