77
88from beartype import BeartypeConf , beartype
99
10+ from vws ._json_utils import JSONValue , json_object
1011from vws .exceptions .custom_exceptions import ServerError
1112from vws .exceptions .model_target_exceptions import (
1213 ModelTargetAuthenticationError ,
2526from vws .reports import ModelTargetDatasetStatusReport
2627from vws .response import Response
2728
28- type _JSONValue = (
29- bool | int | float | str | list [_JSONValue ] | dict [str , _JSONValue ] | None
30- )
31- type _JSONObject = dict [str , _JSONValue ]
29+ type _JSONObject = dict [str , JSONValue ]
3230
3331OAUTH2_ENDPOINT_PATH = "/oauth2/token"
3432OAUTH2_TOKEN_BODY = b"grant_type=client_credentials"
@@ -87,7 +85,7 @@ def access_token_from_response(*, response: Response) -> tuple[str, float]:
8785 if response .status_code != HTTPStatus .OK :
8886 raise ModelTargetOAuth2Error (response = response )
8987
90- response_data = dict [ str , object ]( json . loads ( s = response .text ) )
88+ response_data = json_object ( value = response .text )
9189 access_token = response_data .get ("access_token" )
9290 expires_in = response_data .get ("expires_in" )
9391 if not isinstance (access_token , str ) or not isinstance (
@@ -190,7 +188,7 @@ def _view_dict(*, view: ModelTargetView) -> _JSONObject:
190188 },
191189 }
192190 if view .states is not None :
193- states = list [_JSONValue ](view .states )
191+ states = list [JSONValue ](view .states )
194192 view_dict ["states" ] = states
195193
196194 return view_dict
@@ -308,7 +306,7 @@ def dataset_uuid_from_response(*, response: Response) -> str:
308306 Returns:
309307 The UUID of the created dataset.
310308 """
311- response_data = dict ( json . loads ( s = response .text ) )
309+ response_data = json_object ( value = response .text )
312310 return str (object = response_data ["uuid" ])
313311
314312
@@ -325,7 +323,7 @@ def status_report_from_response(
325323 Returns:
326324 The status of the dataset.
327325 """
328- response_data = dict ( json . loads ( s = response .text ) )
326+ response_data = json_object ( value = response .text )
329327 return ModelTargetDatasetStatusReport .from_response_dict (
330328 response_dict = response_data ,
331329 )
0 commit comments