Skip to content

Commit 1a3d078

Browse files
committed
fix: mypy 38 typing
1 parent 1ef97b3 commit 1a3d078

11 files changed

Lines changed: 79 additions & 91 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
strategy:
1212
fail-fast: false
1313
matrix:
14-
python-version: ["3.8", "3.12", "3.14"]
14+
python-version: ["3.8", "3.10", "3.12", "3.14"]
1515

1616
steps:
1717
- uses: actions/checkout@v4

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "faceit"
3-
version = "0.2.2"
3+
version = "0.2.3"
44
description = "The Python wrapper for the FACEIT API"
55
readme = "README.md"
66
requires-python = ">=3.8"

src/faceit/api/base.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
)
2222
from faceit.utils import warn_stacklevel
2323

24-
from .pagination import AsyncPageIterator, SyncPageIterator
25-
2624
if typing.TYPE_CHECKING:
2725
_ResponseT = typing.TypeVar("_ResponseT", bound=RawAPIResponse)
2826

@@ -66,9 +64,6 @@ class BaseResource(ABC, typing.Generic[ClientT]):
6664
"category": "type",
6765
})
6866

69-
_sync_page_iterator: typing.ClassVar = SyncPageIterator
70-
_async_page_iterator: typing.ClassVar = AsyncPageIterator
71-
7267
def __init__(
7368
self,
7469
client: ClientT,

src/faceit/api/data/championships.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
from typing_extensions import Annotated, TypeAlias
88

99
from faceit.api.base import BaseResource, ModelPlaceholder
10-
from faceit.api.pagination import MaxItemsType, pages
10+
from faceit.api.pagination import (
11+
AsyncPageIterator,
12+
MaxItemsType,
13+
SyncPageIterator,
14+
pages,
15+
)
1116
from faceit.constants import EventCategory, ExpandedField, GameID
1217
from faceit.http import AsyncClient, SyncClient
1318
from faceit.models import Championship, ItemPage
@@ -106,9 +111,7 @@ def all_items(
106111
category: EventCategory = EventCategory.ALL,
107112
max_items: MaxItemsType = pages(30),
108113
) -> typing.Union[typing.List[RawAPIItem], ItemPage[Championship]]:
109-
iterator = self.__class__._sync_page_iterator(
110-
self.items, game, category, max_items=max_items
111-
)
114+
iterator = SyncPageIterator(self.items, game, category, max_items=max_items)
112115
return iterator.collect()
113116

114117
@typing.overload
@@ -327,9 +330,7 @@ async def all_items(
327330
category: EventCategory = EventCategory.ALL,
328331
max_items: MaxItemsType = pages(30),
329332
) -> typing.Union[typing.List[RawAPIItem], ItemPage[Championship]]:
330-
iterator = self.__class__._async_page_iterator(
331-
self.items, game, category, max_items=max_items
332-
)
333+
iterator = AsyncPageIterator(self.items, game, category, max_items=max_items)
333334
return await iterator.collect()
334335

335336
@typing.overload

src/faceit/api/data/games.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
from pydantic import Field, validate_call
77

88
from faceit.api.base import BaseResource, ModelPlaceholder
9-
from faceit.api.pagination import MaxItems, MaxItemsType
9+
from faceit.api.pagination import (
10+
AsyncPageIterator,
11+
MaxItems,
12+
MaxItemsType,
13+
SyncPageIterator,
14+
)
1015
from faceit.http import AsyncClient, SyncClient
1116
from faceit.models import ItemPage # noqa: TC001
1217
from faceit.types import (
@@ -77,7 +82,7 @@ def all_items(
7782
def all_items(
7883
self, max_items: MaxItemsType = MaxItems.SAFE
7984
) -> typing.Union[typing.List[RawAPIItem], ItemPage[ModelNotImplemented]]:
80-
iterator = self.__class__._sync_page_iterator(self.items, max_items=max_items)
85+
iterator = SyncPageIterator(self.items, max_items=max_items)
8186
return iterator.collect()
8287

8388

@@ -130,5 +135,5 @@ async def all_items(
130135
async def all_items(
131136
self, max_items: MaxItemsType = MaxItems.SAFE
132137
) -> typing.Union[typing.List[RawAPIItem], ItemPage[ModelNotImplemented]]:
133-
iterator = self.__class__._async_page_iterator(self.items, max_items=max_items)
138+
iterator = AsyncPageIterator(self.items, max_items=max_items)
134139
return await iterator.collect()

src/faceit/api/data/players.py

Lines changed: 18 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@
1414
RequestPayload,
1515
)
1616
from faceit.api.pagination import (
17+
AsyncPageIterator,
1718
MaxItems,
1819
MaxItemsType,
20+
SyncPageIterator,
1921
TimestampPaginationConfig,
2022
pages,
2123
)
@@ -236,9 +238,7 @@ def all_bans(
236238
def all_bans(
237239
self, player_id: PlayerID, max_items: MaxItemsType = MaxItems.SAFE
238240
) -> typing.Union[typing.List[RawAPIItem], ItemPage[BanEntry]]:
239-
iterator = self.__class__._sync_page_iterator(
240-
self.bans, player_id, max_items=max_items
241-
)
241+
iterator = SyncPageIterator(self.bans, player_id, max_items=max_items)
242242
return iterator.collect()
243243

244244
@typing.overload
@@ -341,8 +341,8 @@ def all_matches_stats(
341341
ItemPage[CS2MatchPlayerStats],
342342
ItemPage[AbstractMatchPlayerStats],
343343
]:
344-
return self.__class__._sync_page_iterator.gather_from_iterator(
345-
self.__class__._sync_page_iterator.unix(
344+
return SyncPageIterator.gather_from_iterator(
345+
SyncPageIterator.unix(
346346
self.matches_stats,
347347
player_id,
348348
game,
@@ -419,8 +419,8 @@ def all_history(
419419
game: GameID,
420420
max_items: MaxItemsType = pages(50),
421421
) -> typing.Union[typing.List[RawAPIItem], ItemPage[Match]]:
422-
return self.__class__._sync_page_iterator.gather_from_iterator(
423-
self.__class__._sync_page_iterator.unix(
422+
return SyncPageIterator.gather_from_iterator(
423+
SyncPageIterator.unix(
424424
self.history,
425425
player_id,
426426
game,
@@ -481,9 +481,7 @@ def all_hubs(
481481
def all_hubs(
482482
self, player_id: PlayerID, max_items: MaxItemsType = MaxItems.SAFE
483483
) -> typing.Union[typing.List[RawAPIItem], ItemPage[Hub]]:
484-
iterator = self.__class__._sync_page_iterator(
485-
self.hubs, player_id, max_items=max_items
486-
)
484+
iterator = SyncPageIterator(self.hubs, player_id, max_items=max_items)
487485
return iterator.collect()
488486

489487
@typing.overload
@@ -566,9 +564,7 @@ def all_teams(
566564
def all_teams(
567565
self, player_id: PlayerID, max_items: MaxItemsType = MaxItems.SAFE
568566
) -> typing.Union[typing.List[RawAPIItem], ItemPage[GeneralTeam]]:
569-
iterator = self.__class__._sync_page_iterator(
570-
self.teams, player_id, max_items=max_items
571-
)
567+
iterator = SyncPageIterator(self.teams, player_id, max_items=max_items)
572568
return iterator.collect()
573569

574570
@typing.overload
@@ -623,9 +619,7 @@ def all_tournaments(
623619
def all_tournaments(
624620
self, player_id: PlayerID, max_items: MaxItemsType = MaxItems.SAFE
625621
) -> typing.Union[typing.List[RawAPIItem], ItemPage[Tournament]]:
626-
iterator = self.__class__._sync_page_iterator(
627-
self.tournaments, player_id, max_items=max_items
628-
)
622+
iterator = SyncPageIterator(self.tournaments, player_id, max_items=max_items)
629623
return iterator.collect()
630624

631625

@@ -723,9 +717,7 @@ async def all_bans(
723717
async def all_bans(
724718
self, player_id: PlayerID, max_items: MaxItemsType = MaxItems.SAFE
725719
) -> typing.Union[typing.List[RawAPIItem], ItemPage[BanEntry]]:
726-
iterator = self.__class__._async_page_iterator(
727-
self.bans, player_id, max_items=max_items
728-
)
720+
iterator = AsyncPageIterator(self.bans, player_id, max_items=max_items)
729721
return await iterator.collect()
730722

731723
@typing.overload
@@ -825,8 +817,8 @@ async def all_matches_stats(
825817
ItemPage[AbstractMatchPlayerStats],
826818
ItemPage[CS2MatchPlayerStats],
827819
]:
828-
return await self.__class__._async_page_iterator.gather_from_iterator(
829-
self.__class__._async_page_iterator.unix(
820+
return await AsyncPageIterator.gather_from_iterator(
821+
AsyncPageIterator.unix(
830822
self.matches_stats,
831823
player_id,
832824
game,
@@ -903,8 +895,8 @@ async def all_history(
903895
game: GameID,
904896
max_items: MaxItemsType = pages(50),
905897
) -> typing.Union[typing.List[RawAPIItem], ItemPage[Match]]:
906-
return await self.__class__._async_page_iterator.gather_from_iterator(
907-
self.__class__._async_page_iterator.unix(
898+
return await AsyncPageIterator.gather_from_iterator(
899+
AsyncPageIterator.unix(
908900
self.history,
909901
player_id,
910902
game,
@@ -965,9 +957,7 @@ async def all_hubs(
965957
async def all_hubs(
966958
self, player_id: PlayerID, max_items: MaxItemsType = MaxItems.SAFE
967959
) -> typing.Union[typing.List[RawAPIItem], ItemPage[Hub]]:
968-
iterator = self.__class__._async_page_iterator(
969-
self.hubs, player_id, max_items=max_items
970-
)
960+
iterator = AsyncPageIterator(self.hubs, player_id, max_items=max_items)
971961
return await iterator.collect()
972962

973963
@typing.overload
@@ -1050,9 +1040,7 @@ async def all_teams(
10501040
async def all_teams(
10511041
self, player_id: PlayerID, max_items: MaxItemsType = MaxItems.SAFE
10521042
) -> typing.Union[typing.List[RawAPIItem], ItemPage[GeneralTeam]]:
1053-
iterator = self.__class__._async_page_iterator(
1054-
self.teams, player_id, max_items=max_items
1055-
)
1043+
iterator = AsyncPageIterator(self.teams, player_id, max_items=max_items)
10561044
return await iterator.collect()
10571045

10581046
@typing.overload
@@ -1107,7 +1095,5 @@ async def all_tournaments(
11071095
async def all_tournaments(
11081096
self, player_id: PlayerID, max_items: MaxItemsType = MaxItems.SAFE
11091097
) -> typing.Union[typing.List[RawAPIItem], ItemPage[Tournament]]:
1110-
iterator = self.__class__._async_page_iterator(
1111-
self.tournaments, player_id, max_items=max_items
1112-
)
1098+
iterator = AsyncPageIterator(self.tournaments, player_id, max_items=max_items)
11131099
return await iterator.collect()

src/faceit/api/data/rankings.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
from pydantic import Field, validate_call
77

88
from faceit.api.base import BaseResource, ModelPlaceholder
9-
from faceit.api.pagination import MaxItemsType, pages
9+
from faceit.api.pagination import (
10+
AsyncPageIterator,
11+
MaxItemsType,
12+
SyncPageIterator,
13+
pages,
14+
)
1015
from faceit.constants import GameID # noqa: TC001
1116
from faceit.http import AsyncClient, SyncClient
1217
from faceit.models import ItemPage # noqa: TC001
@@ -106,7 +111,7 @@ def all_unbounded(
106111
country: typing.Optional[CountryCode] = None,
107112
max_items: MaxItemsType = pages(10),
108113
) -> typing.Union[typing.List[RawAPIItem], ItemPage[ModelNotImplemented]]:
109-
iterator = self.__class__._sync_page_iterator(
114+
iterator = SyncPageIterator(
110115
self.unbounded, game, region, country, max_items=max_items
111116
)
112117
return iterator.collect()
@@ -230,7 +235,7 @@ async def all_unbounded(
230235
country: typing.Optional[CountryCode] = None,
231236
max_items: MaxItemsType = pages(10),
232237
) -> typing.Union[typing.List[RawAPIItem], ItemPage[ModelNotImplemented]]:
233-
iterator = self.__class__._async_page_iterator(
238+
iterator = AsyncPageIterator(
234239
self.unbounded, game, region, country, max_items=max_items
235240
)
236241
return await iterator.collect()

src/faceit/api/data/teams.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@
77
from typing_extensions import Annotated, TypeAlias
88

99
from faceit.api.base import BaseResource, ModelPlaceholder
10-
from faceit.api.pagination import MaxItemsType, pages
10+
from faceit.api.pagination import (
11+
AsyncPageIterator,
12+
MaxItemsType,
13+
SyncPageIterator,
14+
pages,
15+
)
1116
from faceit.constants import GameID # noqa: TC001
1217
from faceit.http import AsyncClient, SyncClient
1318
from faceit.models import ItemPage # noqa: TC001
@@ -124,9 +129,7 @@ def all_tournaments(
124129
def all_tournaments(
125130
self, team_id: _TeamIDValidated, max_items: MaxItemsType = pages(30)
126131
) -> typing.Union[typing.List[RawAPIItem], ItemPage[ModelNotImplemented]]:
127-
iterator = self.__class__._sync_page_iterator(
128-
self.tournaments, team_id, max_items=max_items
129-
)
132+
iterator = SyncPageIterator(self.tournaments, team_id, max_items=max_items)
130133
return iterator.collect()
131134

132135

@@ -221,7 +224,5 @@ async def all_tournaments(
221224
async def all_tournaments(
222225
self, team_id: _TeamIDValidated, max_items: MaxItemsType = pages(30)
223226
) -> typing.Union[typing.List[RawAPIItem], ItemPage[ModelNotImplemented]]:
224-
iterator = self.__class__._async_page_iterator(
225-
self.tournaments, team_id, max_items=max_items
226-
)
227+
iterator = AsyncPageIterator(self.tournaments, team_id, max_items=max_items)
227228
return await iterator.collect()

src/faceit/utils.py

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@
22

33
import inspect
44
import json
5-
import os
65
import reprlib
76
import sys
87
import typing
98
from contextlib import suppress
109
from enum import Enum, auto
1110
from functools import lru_cache, reduce, wraps
1211
from hashlib import sha256
12+
from pathlib import Path
1313
from uuid import UUID
1414

1515
from typing_extensions import Self, TypeIs, deprecated
@@ -222,22 +222,20 @@ def validate_positive_int(value: typing.Any, /, param_name: str = "value") -> in
222222

223223
@lru_cache(maxsize=1)
224224
def _get_ignored_paths() -> typing.Tuple[
225-
typing.Tuple[str, ...],
226-
typing.FrozenSet[str],
225+
typing.Tuple[Path, ...],
226+
typing.FrozenSet[Path],
227227
]:
228-
prefixes: typing.List[str] = []
229-
files: typing.Set[str] = set()
228+
prefixes: typing.List[Path] = []
229+
files: typing.Set[Path] = set()
230230

231231
for mod_name in (__name__.split(".")[0], *_IGNORED_MODULES):
232232
mod = sys.modules.get(mod_name)
233233
if mod is None or not hasattr(mod, "__file__") or mod.__file__ is None:
234234
continue
235235

236-
path = os.path.normcase(os.path.realpath(mod.__file__))
237-
238-
if path.endswith("__init__.py"):
239-
dir_path = os.path.dirname(path) + os.sep # noqa: PTH120
240-
prefixes.append(dir_path)
236+
path = Path(mod.__file__).resolve()
237+
if path.name == "__init__.py":
238+
prefixes.append(path.parent)
241239
else:
242240
files.add(path)
243241

@@ -257,10 +255,10 @@ def warn_stacklevel() -> int:
257255
while frame:
258256
filename = frame.f_code.co_filename
259257
if filename and not filename.startswith("<"):
260-
norm_path = os.path.normcase(os.path.realpath(filename))
261-
is_user_code = (
262-
norm_path not in ignored_files
263-
and not norm_path.startswith(ignored_prefixes)
258+
path = Path(filename).resolve()
259+
is_user_code = path not in ignored_files and not any(
260+
prefix in path.parents or path == prefix
261+
for prefix in ignored_prefixes
264262
)
265263
if is_user_code:
266264
return level

0 commit comments

Comments
 (0)