11"""This module implements the ModelPredict class."""
22
33import json
4- from typing import Type , Dict
5- from aniso8601 import parse_date , parse_datetime
4+ from typing import Any
5+ from aniso8601 import parse_date , parse_datetime # type: ignore
66from flask import request
7- from flask_restx import Resource , Model , fields
7+ from flask_restx import Resource , Model , fields # type: ignore
88from ml_rest_api .api .restx import api , FlaskApiReturnType , MLRestAPINotReadyException
99from ml_rest_api .ml_trained_model .wrapper import trained_model_wrapper
1010
@@ -14,19 +14,19 @@ def build_api_model() -> Model:
1414 Returns a Flask-RESTX Api Model based on the sample dict returned by the trained model wrapper.
1515 This will be used to validate input and automatically generate the Swagger prototype.
1616 """
17- fields_classes_map : Dict = {
17+ fields_classes_map : dict [ str , Any ] = {
1818 "str" : fields .String ,
1919 "int" : fields .Integer ,
2020 "float" : fields .Float ,
2121 "bool" : fields .Boolean ,
2222 "datetime" : fields .DateTime ,
2323 "date" : fields .Date ,
2424 }
25- model_dict : Dict = {}
26- model_sample : Dict = trained_model_wrapper .sample ()
25+ model_dict : dict [ str , Any ] = {}
26+ model_sample : dict [ str , Any ] = trained_model_wrapper .sample ()
2727 if model_sample :
2828 for key , value in model_sample .items ():
29- fields_class : Type [ fields . Raw ] = fields_classes_map .get (
29+ fields_class : Any = fields_classes_map .get (
3030 type (value ).__name__ , fields .String
3131 )
3232 if type (value ).__name__ == "str" :
@@ -44,14 +44,14 @@ def build_api_model() -> Model:
4444 return api .model ("input_vector" , model_dict )
4545
4646
47- ns = api .namespace ( # pylint: disable=invalid-name
47+ ns = api .namespace ( # pylint: disable=invalid-name # type: ignore[misc]
4848 "model" ,
4949 description = "Methods supported by our ML model" ,
5050 validate = bool (trained_model_wrapper .sample ()),
5151)
5252
5353
54- @ns .route ("/predict" )
54+ @ns .route ("/predict" ) # type: ignore[misc]
5555class ModelPredict (Resource ):
5656 """Implements the /model/predict POST method."""
5757
0 commit comments