77from json import JSONDecodeError
88from typing import (
99 Any ,
10- Dict ,
11- List ,
1210 Optional ,
1311 Tuple ,
1412 Union ,
4947)
5048
5149
52- STATUS_CODE_TO_ERROR_MAPPING : Dict [int , Any ] = {
50+ STATUS_CODE_TO_ERROR_MAPPING : dict [int , Any ] = {
5351 400 : BadRequestError ,
5452 401 : UnauthorizedError ,
5553 402 : PaymentError ,
@@ -78,7 +76,7 @@ def __init__(self, client):
7876 self ._client = client
7977
8078 @classmethod
81- def _objects_to_ids (cls , param : Dict [str , Any ]) -> Dict [str , Any ]:
79+ def _objects_to_ids (cls , param : dict [str , Any ]) -> dict [str , Any ]:
8280 """If providing an object as a parameter to another object,
8381 only pass along the ID so the API will use the object reference correctly.
8482 """
@@ -97,10 +95,10 @@ def _objects_to_ids(cls, param: Dict[str, Any]) -> Dict[str, Any]:
9795
9896 @staticmethod
9997 def form_encode_params (
100- data : Dict [str , Any ],
101- parent_keys : Optional [List [str ]] = None ,
102- parent_dict : Optional [Dict [str , Any ]] = None ,
103- ) -> Dict :
98+ data : dict [str , Any ],
99+ parent_keys : Optional [list [str ]] = None ,
100+ parent_dict : Optional [dict [str , Any ]] = None ,
101+ ) -> dict :
104102 """Form-encode a multi-layer dictionary to a one-layer dictionary."""
105103 result = parent_dict or {}
106104 keys = parent_keys or []
@@ -116,7 +114,7 @@ def form_encode_params(
116114 return result
117115
118116 @staticmethod
119- def _build_dict_key (keys : List [str ]) -> str :
117+ def _build_dict_key (keys : list [str ]) -> str :
120118 """Build a dict key from a list of keys.
121119 Example: [code, number] -> code[number]
122120 """
@@ -131,9 +129,9 @@ def request(
131129 self ,
132130 method : RequestMethod ,
133131 url : str ,
134- params : Optional [Dict [str , Any ]] = None ,
132+ params : Optional [dict [str , Any ]] = None ,
135133 beta : bool = False ,
136- ) -> Dict [str , Any ]:
134+ ) -> dict [str , Any ]:
137135 """Make a request to the EasyPost API."""
138136 if params is None :
139137 params = {}
@@ -153,7 +151,7 @@ def request_raw(
153151 self ,
154152 method : RequestMethod ,
155153 url : str ,
156- params : Optional [Dict [str , Any ]] = None ,
154+ params : Optional [dict [str , Any ]] = None ,
157155 beta : bool = False ,
158156 ) -> Tuple [str , int ]:
159157 """Internal logic required to make a request to the EasyPost API."""
@@ -239,7 +237,7 @@ def request_raw(
239237
240238 return http_body , http_status
241239
242- def interpret_response (self , http_body : str , http_status : int ) -> Dict [str , Any ]:
240+ def interpret_response (self , http_body : str , http_status : int ) -> dict [str , Any ]:
243241 """Interpret the response body we receive from the API."""
244242 if http_status == 204 :
245243 # HTTP 204 does not have any response body and we can just return here
@@ -259,9 +257,9 @@ def requests_request(
259257 self ,
260258 method : RequestMethod ,
261259 abs_url : str ,
262- headers : Dict [str , Any ],
263- params : Dict [str , Any ],
264- ) -> Tuple [str , int , Dict [str , Any ]]:
260+ headers : dict [str , Any ],
261+ params : dict [str , Any ],
262+ ) -> Tuple [str , int , dict [str , Any ]]:
265263 """Make a request by using the `request` library."""
266264 if method in [RequestMethod .GET , RequestMethod .DELETE ]:
267265 url_params = params
@@ -299,9 +297,9 @@ def urlfetch_request(
299297 self ,
300298 method : RequestMethod ,
301299 abs_url : str ,
302- headers : Dict [str , Any ],
303- params : Dict [str , Any ],
304- ) -> Tuple [str , int , Dict [str , Any ]]:
300+ headers : dict [str , Any ],
301+ params : dict [str , Any ],
302+ ) -> Tuple [str , int , dict [str , Any ]]:
305303 """Make a request by using the `urlfetch` library."""
306304 fetch_args = {
307305 "method" : method .value ,
@@ -329,7 +327,7 @@ def urlfetch_request(
329327
330328 return result .content , result .status_code , result .headers
331329
332- def handle_api_error (self , http_status : int , http_body : str , response : Dict [str , Any ]) -> None :
330+ def handle_api_error (self , http_status : int , http_body : str , response : dict [str , Any ]) -> None :
333331 """Handles API errors returned from the EasyPost API."""
334332 try :
335333 error = response ["error" ]
@@ -357,7 +355,7 @@ def _utf8(self, value: Union[str, bytes]) -> str:
357355 return value .decode (encoding = "utf-8" )
358356 return value
359357
360- def encode_url_params (self , params : Dict [str , Any ], method : RequestMethod ) -> Union [str , None ]:
358+ def encode_url_params (self , params : dict [str , Any ], method : RequestMethod ) -> Union [str , None ]:
361359 """Encode params for a URL."""
362360 if method not in [RequestMethod .GET , RequestMethod .DELETE ]:
363361 raise EasyPostError (INVALID_REQUEST_PARAMETERS_ERROR )
@@ -373,7 +371,7 @@ def encode_url_params(self, params: Dict[str, Any], method: RequestMethod) -> Un
373371
374372 return urlencode (query = converted_params )
375373
376- def add_params_to_url (self , url : str , params : Dict [str , Any ], method : RequestMethod ) -> str :
374+ def add_params_to_url (self , url : str , params : dict [str , Any ], method : RequestMethod ) -> str :
377375 """Add params to the URL."""
378376 if method not in [RequestMethod .GET , RequestMethod .DELETE ]:
379377 raise EasyPostError (INVALID_REQUEST_PARAMETERS_ERROR )
0 commit comments