Skip to content

Commit 15d6bbb

Browse files
committed
lint: minor cleanup
1 parent 195718d commit 15d6bbb

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

tests/test_ratelimits.py

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1+
import asyncio
12
from datetime import datetime, timedelta
3+
24
from httpx import Response
35
import pytest
4-
import asyncio
56

6-
from tests.common import get_response_json
77
from xbox.webapi.api.provider.ratelimitedprovider import RateLimitedProvider
8-
98
from xbox.webapi.common.exceptions import RateLimitExceededException, XboxException
109
from xbox.webapi.common.ratelimits import CombinedRateLimit
1110
from xbox.webapi.common.ratelimits.models import TimePeriod
1211

12+
from tests.common import get_response_json
13+
1314

1415
def helper_test_combinedratelimit(
1516
crl: CombinedRateLimit, burstLimit: int, sustainLimit: int
@@ -18,8 +19,8 @@ def helper_test_combinedratelimit(
1819
sustain = crl.get_limits_by_period(TimePeriod.SUSTAIN)
1920

2021
# These functions should return a list with one element
21-
assert type(burst) == list
22-
assert type(sustain) == list
22+
assert isinstance(burst, list)
23+
assert isinstance(sustain, list)
2324

2425
assert len(burst) == 1
2526
assert len(sustain) == 1
@@ -111,7 +112,7 @@ async def make_request():
111112
route = respx_mock.get("https://social.xboxlive.com").mock(
112113
return_value=Response(200, json=get_response_json("people_summary_own"))
113114
)
114-
ret = await xbl_client.people.get_friends_summary_own()
115+
await xbl_client.people.get_friends_summary_own()
115116

116117
assert route.called
117118

@@ -175,7 +176,7 @@ async def make_request():
175176
route = respx_mock.get("https://social.xboxlive.com").mock(
176177
return_value=Response(200, json=get_response_json("people_summary_own"))
177178
)
178-
ret = await xbl_client.people.get_friends_summary_own()
179+
await xbl_client.people.get_friends_summary_own()
179180

180181
assert route.called
181182

xbox/webapi/api/provider/ratelimitedprovider.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@
44
Subclassed by providers with rate limit support
55
"""
66

7-
from typing import Union, Dict
7+
from typing import Dict, Union
8+
89
from xbox.webapi.api.provider.baseprovider import BaseProvider
910
from xbox.webapi.common.exceptions import XboxException
10-
from xbox.webapi.common.ratelimits.models import LimitType, ParsedRateLimit, TimePeriod
1111
from xbox.webapi.common.ratelimits import CombinedRateLimit
12+
from xbox.webapi.common.ratelimits.models import LimitType, ParsedRateLimit, TimePeriod
1213

1314

1415
class RateLimitedProvider(BaseProvider):
@@ -63,9 +64,9 @@ def __parse_rate_limit_key(
6364
self, key: Union[int, Dict[str, int]], period: TimePeriod
6465
) -> ParsedRateLimit:
6566
key_type = type(key)
66-
if key_type == int:
67+
if isinstance(key_type, int):
6768
return ParsedRateLimit(read=key, write=key, period=period)
68-
elif key_type == dict:
69+
elif isinstance(key_type, dict):
6970
# TODO: schema here?
7071
# Since the key-value pairs match we can just pass the dict to the model
7172
return ParsedRateLimit(**key, period=period)

xbox/webapi/common/ratelimits/__init__.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
1+
from abc import ABCMeta, abstractmethod
12
from datetime import datetime, timedelta
2-
from typing import Union, List
3+
from typing import List, Union
34

45
from xbox.webapi.common.ratelimits.models import (
6+
IncrementResult,
7+
LimitType,
58
ParsedRateLimit,
69
TimePeriod,
7-
LimitType,
8-
IncrementResult,
910
)
1011

11-
from abc import ABCMeta, abstractmethod
12-
1312

1413
class RateLimit(metaclass=ABCMeta):
1514
"""
@@ -209,7 +208,7 @@ def get_reset_after(self) -> Union[datetime, None]:
209208

210209
# Construct a new list with only elements of instance datetime
211210
# (Effectively filtering out any None elements)
212-
dates_valid = [elem for elem in dates if type(elem) == datetime]
211+
dates_valid = [elem for elem in dates if isinstance(elem, datetime)]
213212

214213
# If dates_valid has any elements, return the one with the *later* timestamp.
215214
# This means that if two or more limits have been exceeded, we wait for both to have reset (by returning the later timestamp)
@@ -238,7 +237,7 @@ def get_limits_by_period(self, period: TimePeriod) -> List[SingleRateLimit]:
238237
def is_exceeded(self) -> bool:
239238
"""
240239
This function returns `True` if **any** rate limit has been exceeded.
241-
240+
242241
It behaves like an OR logic gate.
243242
"""
244243

0 commit comments

Comments
 (0)