Skip to content

Commit b8e05c2

Browse files
committed
Run ruff check --fix
1 parent 521ca3e commit b8e05c2

35 files changed

+143
-79
lines changed

examples/main.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import asyncio
24
import logging
35
import sys

src/saic_ismart_client_ng/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from saic_ismart_client_ng.api.message import SaicMessageApi
24
from saic_ismart_client_ng.api.user import SaicUserApi
35
from saic_ismart_client_ng.api.vehicle import SaicVehicleApi as SaicVehicleApi

src/saic_ismart_client_ng/api/base.py

Lines changed: 30 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
from __future__ import annotations
2+
3+
from abc import ABC
4+
from dataclasses import asdict
15
import datetime
26
import json
37
import logging
4-
from abc import ABC
5-
from dataclasses import asdict
6-
from typing import Type, Optional, Any, TypeVar
8+
from typing import Any, Optional, Type, TypeVar
79

810
import dacite
911
import httpx
12+
from httpx._types import HeaderTypes, QueryParamTypes
1013
import tenacity
11-
from httpx._types import QueryParamTypes, HeaderTypes
1214

1315
from saic_ismart_client_ng.api.schema import LoginResp
1416
from saic_ismart_client_ng.crypto_utils import sha1_hex_digest
@@ -112,7 +114,7 @@ async def __execute_api_call(
112114
headers: Optional[HeaderTypes] = None,
113115
allow_null_body: bool = False,
114116
) -> Optional[T]:
115-
url = f"{self.__configuration.base_uri}{path[1:] if path.startswith('/') else path}"
117+
url = f"{self.__configuration.base_uri}{path.removeprefix('/')}"
116118
json_body = asdict(body) if body else None
117119
req = httpx.Request(
118120
method, url, params=params, headers=headers, data=form_body, json=json_body
@@ -195,27 +197,24 @@ async def __deserialize(
195197
event_id=request_event_id,
196198
return_code=return_code,
197199
)
198-
else:
199-
logger.error(
200-
f"API call return code is not acceptable: {return_code}: {response.text}. Headers: {response.headers}"
201-
)
202-
raise SaicApiException(error_message, return_code=return_code)
200+
logger.error(
201+
f"API call return code is not acceptable: {return_code}: {response.text}. Headers: {response.headers}"
202+
)
203+
raise SaicApiException(error_message, return_code=return_code)
203204

204205
if data_class is None:
205206
return None
206-
elif "data" in json_data:
207+
if "data" in json_data:
207208
if data_class is str:
208209
return json.dumps(json_data["data"])
209-
elif data_class is dict:
210+
if data_class is dict:
210211
return json_data["data"]
211-
else:
212-
return dacite.from_dict(data_class, json_data["data"])
213-
elif allow_null_body:
212+
return dacite.from_dict(data_class, json_data["data"])
213+
if allow_null_body:
214214
return None
215-
else:
216-
raise SaicApiException(
217-
f"Failed to deserialize response, missing 'data' field: {response.text}"
218-
)
215+
raise SaicApiException(
216+
f"Failed to deserialize response, missing 'data' field: {response.text}"
217+
)
219218

220219
except SaicApiException as se:
221220
raise se
@@ -230,16 +229,14 @@ async def __deserialize(
230229
raise SaicLogoutException(
231230
response.text, response.status_code
232231
) from e
233-
else:
234-
logger.error(
235-
f"API call failed: {response.status_code} {response.text}",
236-
exc_info=e,
237-
)
238-
raise SaicApiException(response.text, response.status_code) from e
239-
else:
240-
raise SaicApiException(
241-
f"Failed to deserialize response: {e}. Original json was {response.text}"
242-
) from e
232+
logger.error(
233+
f"API call failed: {response.status_code} {response.text}",
234+
exc_info=e,
235+
)
236+
raise SaicApiException(response.text, response.status_code) from e
237+
raise SaicApiException(
238+
f"Failed to deserialize response: {e}. Original json was {response.text}"
239+
) from e
243240

244241
def logout(self):
245242
self.__api_client.user_token = ""
@@ -277,13 +274,12 @@ def saic_api_retry_policy(retry_state):
277274
if isinstance(wrapped_exception, SaicApiRetryException):
278275
logger.debug("Retrying since we got SaicApiRetryException")
279276
return True
280-
elif isinstance(wrapped_exception, SaicLogoutException):
277+
if isinstance(wrapped_exception, SaicLogoutException):
281278
logger.error("Not retrying since we got logged out")
282279
return False
283-
elif isinstance(wrapped_exception, SaicApiException):
280+
if isinstance(wrapped_exception, SaicApiException):
284281
logger.error("Not retrying since we got a generic exception")
285282
return False
286-
else:
287-
logger.error(f"Not retrying {retry_state.args} {wrapped_exception}")
288-
return False
283+
logger.error(f"Not retrying {retry_state.args} {wrapped_exception}")
284+
return False
289285
return False

src/saic_ismart_client_ng/api/message/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from typing import Optional, Union
24

35
from saic_ismart_client_ng.api.base import AbstractSaicApi

src/saic_ismart_client_ng/api/message/schema.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
from __future__ import annotations
2+
3+
from dataclasses import dataclass, field
14
import datetime
25
import logging
3-
from dataclasses import dataclass, field
46
from typing import List, Optional, Union
57

68
LOGGER = logging.getLogger(__name__)
@@ -49,10 +51,9 @@ def message_time(self) -> datetime.datetime:
4951
def read_status(self) -> str:
5052
if self.readStatus is None:
5153
return "unknown"
52-
elif self.readStatus == 0:
54+
if self.readStatus == 0:
5355
return "unread"
54-
else:
55-
return "read"
56+
return "read"
5657

5758
@property
5859
def details(self) -> str:

src/saic_ismart_client_ng/api/schema.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import logging
1+
from __future__ import annotations
2+
23
from dataclasses import dataclass
34
from enum import Enum
5+
import logging
46
from typing import Optional
57

68
logger = logging.getLogger(__name__)

src/saic_ismart_client_ng/api/serialization_utils.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
import base64
24
import logging
35
from typing import Optional
@@ -11,7 +13,7 @@ def decode_bytes(
1113
try:
1214
if isinstance(input_value, str):
1315
return base64.b64decode(input_value)
14-
elif isinstance(input_value, int):
16+
if isinstance(input_value, int):
1517
return input_value.to_bytes((input_value.bit_length() + 7) // 8, "big")
1618
except Exception as e:
1719
__LOGGER.error("Failed to decode %s: %s", field_name, input_value, exc_info=e)

src/saic_ismart_client_ng/api/user/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from saic_ismart_client_ng.api.base import AbstractSaicApi
24
from saic_ismart_client_ng.api.user.schema import UserTimezoneResp
35

src/saic_ismart_client_ng/api/user/schema.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from __future__ import annotations
2+
13
from dataclasses import dataclass
24
from typing import Optional
35

src/saic_ismart_client_ng/api/vehicle/__init__.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
1+
from __future__ import annotations
2+
13
import tenacity
24

35
from saic_ismart_client_ng.api.base import AbstractSaicApi
46
from saic_ismart_client_ng.api.vehicle.schema import (
5-
VehicleListResp,
6-
VehicleStatusResp,
7-
VehicleControlReq,
8-
VehicleControlResp,
97
RvcParams,
10-
RvcReqType,
118
RvcParamsId,
9+
RvcReqType,
10+
VehicleControlReq,
11+
VehicleControlResp,
12+
VehicleListResp,
13+
VehicleStatusResp,
1214
)
1315
from saic_ismart_client_ng.crypto_utils import sha256_hex_digest
1416

0 commit comments

Comments
 (0)