generated from pavel.muhortov/template-bash
add Do.args_valid()
This commit is contained in:
parent
3e938f20cc
commit
db76bb8e0b
|
@ -1524,6 +1524,37 @@ class FFmpeg:
|
|||
return None
|
||||
|
||||
|
||||
class Do():
|
||||
"""Set of various methods (functions) for routine.
|
||||
"""
|
||||
@staticmethod
|
||||
def args_valid(arguments: dict, annotations: dict) -> bool:
|
||||
"""Arguments type validating by annotations.
|
||||
|
||||
Args:
|
||||
arguments (dict): 'locals()' immediately after starting the function.
|
||||
annotations (dict): function.name.__annotations__.
|
||||
|
||||
Raises:
|
||||
TypeError: type of argument is not equal type in annotation.
|
||||
|
||||
Returns:
|
||||
bool: True if argument types are valid.
|
||||
"""
|
||||
for var_name, var_type in annotations.items():
|
||||
if not var_name == 'return':
|
||||
if not isinstance(arguments[var_name], var_type):
|
||||
raise TypeError(""
|
||||
+ "type of '"
|
||||
+ var_name
|
||||
+ "' = "
|
||||
+ str(arguments[var_name])
|
||||
+ " is not "
|
||||
+ str(var_type)
|
||||
)
|
||||
return True
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
time_start = datetime.now()
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user