Skip to content

Commit 8757038

Browse files
authored
Static-typing (#47)
* Implement new pyright workflow * fix typing issues * update pyright action * update python path * remove unncessary type ignore
1 parent b00e071 commit 8757038

File tree

5 files changed

+35
-11
lines changed

5 files changed

+35
-11
lines changed

.github/workflows/lint.yml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,28 @@ jobs:
2222

2323
- uses: astral-sh/ruff-action@v3
2424
with:
25-
version: ${{ steps.ruff-version.outputs.version }}
25+
version: ${{ steps.ruff-version.outputs.version }}
26+
pyright:
27+
runs-on: ubuntu-latest
28+
strategy:
29+
fail-fast: false
30+
matrix:
31+
python-version: [ '3.10', '3.x' ]
32+
name: pyright ${{ matrix.python-version }}
33+
steps:
34+
- uses: actions/checkout@v5
35+
- name: Setup Python ${{ matrix.python-version }}
36+
uses: actions/setup-python@v6
37+
with:
38+
python-version: ${{ matrix.python-version }}
39+
cache: "pip" # Cache the pip packages to speed up the workflow
40+
- name: Set up UV
41+
uses: astral-sh/setup-uv@v6
42+
- name: Install Dependencies and Package
43+
run: uv sync --all-extras
44+
- name: Run Pyright
45+
uses: jakebailey/pyright-action@v2
46+
with:
47+
version: '1.1.407'
48+
annotate: ${{ matrix.python-version != '3.x' }}
49+
python-path: '.venv/bin/python'

fortnite_api/new.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from __future__ import annotations
2626

2727
import datetime
28-
from typing import Any, Generic
28+
from typing import Any, Generic, cast
2929

3030
from .abc import ReconstructAble
3131
from .cosmetics import (
@@ -208,7 +208,7 @@ def _parse_new_cosmetic(
208208
internal_key: str,
209209
cosmetic_class: type[CosmeticT],
210210
) -> NewCosmetic[CosmeticT]:
211-
cosmetic_items: list[dict[str, Any]] = get_with_fallback(self._items, internal_key, list)
211+
cosmetic_items = cast(list[dict[str, Any]], get_with_fallback(self._items, internal_key, list))
212212

213213
last_addition_str = self._last_additions[internal_key]
214214
last_addition: datetime.datetime | None = last_addition_str and parse_time(last_addition_str)

fortnite_api/proxies.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ def _transform_at(self, index: SupportsIndex) -> T:
6767
data = super().__getitem__(index)
6868
if isinstance(data, dict):
6969
# Narrow the type of data to Dict[str, Any]
70-
raw_data: dict[K_co, V_co] = data
70+
raw_data = cast(dict[K_co, V_co], data)
7171
result = self._transform_data(raw_data)
7272
super().__setitem__(index, result)
7373
else:
@@ -78,7 +78,7 @@ def _transform_at(self, index: SupportsIndex) -> T:
7878
def _transform_all(self):
7979
for index, entry in enumerate(self):
8080
if isinstance(entry, dict):
81-
raw_data: dict[K_co, V_co] = entry
81+
raw_data = cast(dict[K_co, V_co], entry)
8282
result = self._transform_data(raw_data)
8383
super().__setitem__(index, result)
8484

fortnite_api/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import datetime
2828
from collections.abc import Callable
29-
from typing import TYPE_CHECKING, Any, TypeVar
29+
from typing import TYPE_CHECKING, Any, TypeVar, cast
3030

3131
K_co = TypeVar('K_co', bound='Hashable', covariant=True)
3232
V_co = TypeVar('V_co', covariant=True)
@@ -36,7 +36,7 @@
3636
from collections.abc import Hashable
3737

3838
try:
39-
import orjson # type: ignore
39+
import orjson
4040

4141
_has_orjson: bool = True
4242
except ImportError:
@@ -201,7 +201,7 @@ def _transform_dict_for_get_request(data: dict[str, Any]) -> dict[str, Any]:
201201
updated[key] = str(value).lower()
202202

203203
elif isinstance(value, dict):
204-
inner: dict[str, Any] = value # narrow the dict type to pass it along (should always be [str, Any])
204+
inner = cast(dict[str, Any], value) # narrow the dict type to pass it along (should always be [str, Any])
205205
updated[key] = _transform_dict_for_get_request(inner)
206206

207207
if '_' in key:

tests/client/test_client_hybrid.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
import inspect
2828
import logging
2929
from collections.abc import Callable, Coroutine
30-
from typing import TYPE_CHECKING, Any, Concatenate, Generic, TypeAlias, TypeVar
30+
from typing import TYPE_CHECKING, Any, Concatenate, Generic, TypeAlias, TypeVar, cast
3131

3232
import pytest
3333
import requests
@@ -78,8 +78,8 @@ def _validate_results(self, async_res: T, sync_res: T) -> None:
7878
if isinstance(async_res, fortnite_api.ReconstructAble):
7979
assert isinstance(sync_res, fortnite_api.ReconstructAble)
8080

81-
sync_res_narrowed: fortnite_api.ReconstructAble[Any, fortnite_api.http.SyncHTTPClient] = sync_res
82-
async_res_narrowed: fortnite_api.ReconstructAble[Any, fortnite_api.http.HTTPClient] = async_res
81+
sync_res_narrowed = cast(fortnite_api.ReconstructAble[Any, fortnite_api.http.SyncHTTPClient], sync_res)
82+
async_res_narrowed = cast(fortnite_api.ReconstructAble[Any, fortnite_api.http.HTTPClient], async_res)
8383

8484
async_raw_data = sync_res_narrowed.to_dict()
8585
sync_raw_data = sync_res_narrowed.to_dict()

0 commit comments

Comments
 (0)