|
1 | 1 | from ast import literal_eval |
2 | | -from functools import wraps |
3 | | -from inspect import getfullargspec |
4 | 2 | from pathlib import Path |
5 | | -from typing import get_type_hints |
6 | 3 | from typing import List |
7 | 4 | from typing import Optional |
8 | 5 | from typing import Tuple |
9 | 6 | from typing import Union |
10 | 7 |
|
11 | 8 | import boto3 |
12 | 9 | import pandas as pd |
13 | | -from lib.core.exceptions import AppValidationException |
14 | 10 | from superannotate.lib.app.exceptions import PathError |
15 | 11 | from superannotate.lib.core import PIXEL_ANNOTATION_POSTFIX |
16 | 12 | from superannotate.lib.core import VECTOR_ANNOTATION_POSTFIX |
@@ -121,45 +117,3 @@ def metric_is_plottable(key): |
121 | 117 | if key == "total_loss" or "mIoU" in key or "mAP" in key or key == "iteration": |
122 | 118 | return True |
123 | 119 | return False |
124 | | - |
125 | | - |
126 | | -def check_types(obj, **kwargs): |
127 | | - hints = get_type_hints(obj) |
128 | | - |
129 | | - errors = [] |
130 | | - for attr_name, attr_type in hints.items(): |
131 | | - if attr_name == "return": |
132 | | - continue |
133 | | - try: |
134 | | - if getattr(attr_type, "__origin__") and attr_type.__origin__ is list: |
135 | | - if attr_type.__args__: |
136 | | - for elem in kwargs[attr_name]: |
137 | | - if type(elem) in attr_type.__args__: |
138 | | - continue |
139 | | - else: |
140 | | - errors.append(f"Invalid input {attr_name}") |
141 | | - elif not isinstance(kwargs[attr_name], list): |
142 | | - errors.append(f"Argument {attr_name} is not of type {attr_type}") |
143 | | - elif getattr(attr_type, "__origin__") and attr_type.__origin__ is Union: |
144 | | - if kwargs.get(attr_name) and not isinstance( |
145 | | - kwargs[attr_name], attr_type.__args__ |
146 | | - ): |
147 | | - errors.append(f"Argument {attr_name} is not of type {attr_type}") |
148 | | - elif kwargs.get(attr_name) and not isinstance(kwargs[attr_name], attr_type): |
149 | | - errors.append(f"Argument {attr_name} is not of type {attr_type}") |
150 | | - except Exception as _: |
151 | | - pass |
152 | | - return errors |
153 | | - |
154 | | - |
155 | | -def validate_input(decorator): |
156 | | - @wraps(decorator) |
157 | | - def wrapped_decorator(*args, **kwargs): |
158 | | - func_args = getfullargspec(decorator)[0] |
159 | | - kwargs.update(dict(zip(func_args, args))) |
160 | | - errors = check_types(decorator, **kwargs) |
161 | | - if errors: |
162 | | - raise AppValidationException("\n".join(errors)) |
163 | | - return decorator(**kwargs) |
164 | | - |
165 | | - return wrapped_decorator |
0 commit comments