Skip to content

Commit cf69466

Browse files
authored
Enable ruff ANN rule and fix annotations (#25)
1 parent fbd78c3 commit cf69466

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+433
-191
lines changed

pyproject.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ line-length = 88
4747
target-version = "py311"
4848

4949
[tool.ruff.lint]
50-
select = ["E4", "E7", "E9", "F", "UP", "S"]
51-
ignore = []
50+
select = ["E4", "E7", "E9", "F", "UP", "S", "ANN"]
51+
# select = ["ALL"]
52+
ignore = ["ANN003", "ANN401"]
5253

5354

5455
[tool.ruff.lint.per-file-ignores]

readme_example.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
from httpx import HTTPStatusError
55

6-
from pythonxbox.webapi.api.client import XboxLiveClient
7-
from pythonxbox.webapi.authentication.manager import AuthenticationManager
8-
from pythonxbox.webapi.authentication.models import OAuth2TokenResponse
9-
from pythonxbox.webapi.common.signed_session import SignedSession
10-
from pythonxbox.webapi.scripts import CLIENT_ID, CLIENT_SECRET, TOKENS_FILE
6+
from pythonxbox.api.client import XboxLiveClient
7+
from pythonxbox.authentication.manager import AuthenticationManager
8+
from pythonxbox.authentication.models import OAuth2TokenResponse
9+
from pythonxbox.common.signed_session import SignedSession
10+
from pythonxbox.scripts import CLIENT_ID, CLIENT_SECRET, TOKENS_FILE
1111

1212
"""
1313
This uses the global default client identification by OpenXbox
@@ -23,7 +23,7 @@
2323
"""
2424

2525

26-
async def async_main():
26+
async def async_main() -> None:
2727
# Create a HTTP client session
2828
async with SignedSession() as session:
2929
"""

src/pythonxbox/api/client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636

3737

3838
class Session:
39-
def __init__(self, auth_mgr: AuthenticationManager):
39+
def __init__(self, auth_mgr: AuthenticationManager) -> None:
4040
self._auth_mgr = auth_mgr
4141
self._cv = CorrelationVector()
4242

@@ -125,7 +125,7 @@ def __init__(
125125
self,
126126
auth_mgr: AuthenticationManager,
127127
language: XboxLiveLanguage = DefaultXboxLiveLanguages.United_States,
128-
):
128+
) -> None:
129129
self._auth_mgr = auth_mgr
130130
self.session = Session(auth_mgr)
131131
self._language = language

src/pythonxbox/api/language.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,13 @@
44

55

66
class XboxLiveLanguage:
7-
def __init__(self, name, short_id, identifier, locale):
7+
def __init__(
8+
self,
9+
name: str,
10+
short_id: str,
11+
identifier: str,
12+
locale: str,
13+
) -> None:
814
"""
915
Initialize a new instance of :class:`XboxLiveLanguage`
1016

src/pythonxbox/api/provider/account/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class AccountProvider(BaseProvider):
1212
HEADERS_USER_MGT = {"x-xbl-contract-version": "1"}
1313
HEADERS_ACCOUNT = {"x-xbl-contract-version": "2"}
1414

15-
async def claim_gamertag(self, xuid, gamertag, **kwargs) -> ClaimGamertagResult:
15+
async def claim_gamertag(
16+
self, xuid: str, gamertag: str, **kwargs
17+
) -> ClaimGamertagResult:
1618
"""
1719
Claim gamertag
1820
@@ -40,7 +42,7 @@ async def claim_gamertag(self, xuid, gamertag, **kwargs) -> ClaimGamertagResult:
4042
resp.raise_for_status()
4143

4244
async def change_gamertag(
43-
self, xuid, gamertag, preview=False, **kwargs
45+
self, xuid: str, gamertag: str, preview: bool = False, **kwargs
4446
) -> ChangeGamertagResult:
4547
"""
4648
Change your gamertag.

src/pythonxbox/api/provider/achievements/__init__.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class AchievementsProvider(RateLimitedProvider):
2121
RATE_LIMITS = {"burst": 100, "sustain": 300}
2222

2323
async def get_achievements_detail_item(
24-
self, xuid, service_config_id, achievement_id, **kwargs
24+
self, xuid: str, service_config_id: str, achievement_id: str, **kwargs
2525
) -> AchievementResponse:
2626
"""
2727
Get achievement detail for specific item
@@ -45,7 +45,7 @@ async def get_achievements_detail_item(
4545
return AchievementResponse(**resp.json())
4646

4747
async def get_achievements_xbox360_all(
48-
self, xuid, title_id, **kwargs
48+
self, xuid: str, title_id: str, **kwargs
4949
) -> Achievement360Response:
5050
"""
5151
Get all achievements for specific X360 title Id
@@ -70,7 +70,7 @@ async def get_achievements_xbox360_all(
7070
return Achievement360Response(**resp.json())
7171

7272
async def get_achievements_xbox360_earned(
73-
self, xuid, title_id, **kwargs
73+
self, xuid: str, title_id: str, **kwargs
7474
) -> Achievement360Response:
7575
"""
7676
Get earned achievements for specific X360 title id
@@ -95,7 +95,7 @@ async def get_achievements_xbox360_earned(
9595
return Achievement360Response(**resp.json())
9696

9797
async def get_achievements_xbox360_recent_progress_and_info(
98-
self, xuid, **kwargs
98+
self, xuid: str, **kwargs
9999
) -> Achievement360ProgressResponse:
100100
"""
101101
Get recent achievement progress and information
@@ -117,7 +117,7 @@ async def get_achievements_xbox360_recent_progress_and_info(
117117
return Achievement360ProgressResponse(**resp.json())
118118

119119
async def get_achievements_xboxone_gameprogress(
120-
self, xuid, title_id, **kwargs
120+
self, xuid: str, title_id: str, **kwargs
121121
) -> AchievementResponse:
122122
"""
123123
Get gameprogress for Xbox One title
@@ -142,7 +142,7 @@ async def get_achievements_xboxone_gameprogress(
142142
return AchievementResponse(**resp.json())
143143

144144
async def get_achievements_xboxone_recent_progress_and_info(
145-
self, xuid, **kwargs
145+
self, xuid: str, **kwargs
146146
) -> RecentProgressResponse:
147147
"""
148148
Get recent achievement progress and information

src/pythonxbox/api/provider/baseprovider.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
Subclassed by every *real* provider
55
"""
66

7+
from typing import TYPE_CHECKING
8+
9+
10+
if TYPE_CHECKING:
11+
from pythonxbox.api.client import XboxLiveClient
12+
713

814
class BaseProvider:
9-
def __init__(self, client):
15+
def __init__(self, client: "XboxLiveClient") -> None:
1016
"""
1117
Initialize an the BaseProvider
1218

src/pythonxbox/api/provider/catalog/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class SkuProperties(PascalCaseModel):
250250
is_bundle: bool
251251

252252
@field_validator("last_update_date", mode="before", check_fields=True)
253-
def validator(x):
253+
def validator(x: "SkuProperties") -> "SkuProperties":
254254
return x or None
255255

256256

src/pythonxbox/api/provider/presence/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class PresenceProvider(BaseProvider):
1717

1818
async def get_presence(
1919
self,
20-
xuid,
20+
xuid: str,
2121
presence_level: PresenceLevel = PresenceLevel.USER,
2222
**kwargs,
2323
) -> PresenceItem:

src/pythonxbox/api/provider/ratelimitedprovider.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,21 @@
44
Subclassed by providers with rate limit support
55
"""
66

7+
from typing import TYPE_CHECKING
78
from pythonxbox.api.provider.baseprovider import BaseProvider
89
from pythonxbox.common.exceptions import XboxException
910
from pythonxbox.common.ratelimits import CombinedRateLimit
1011
from pythonxbox.common.ratelimits.models import LimitType, ParsedRateLimit, TimePeriod
1112

13+
if TYPE_CHECKING:
14+
from pythonxbox.api.client import XboxLiveClient
15+
1216

1317
class RateLimitedProvider(BaseProvider):
1418
# dict -> Dict (typing.dict) https://stackoverflow.com/a/63460173
1519
RATE_LIMITS: dict[str, int | dict[str, int]]
1620

17-
def __init__(self, client):
21+
def __init__(self, client: "XboxLiveClient") -> None:
1822
"""
1923
Initialize Baseclass
2024
@@ -39,7 +43,7 @@ def __init__(self, client):
3943
"RateLimitedProvider as parent class but RATE_LIMITS not set!"
4044
)
4145

42-
def __handle_rate_limit_setup(self):
46+
def __handle_rate_limit_setup(self) -> None:
4347
# Retrieve burst and sustain from the dict
4448
burst_key = self.RATE_LIMITS["burst"]
4549
sustain_key = self.RATE_LIMITS["sustain"]

0 commit comments

Comments
 (0)