Skip to content

Commit

Permalink
rplaced kwargs with optional, named keyword arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
joeyagreco committed Feb 13, 2024
1 parent 1b32b39 commit 402f354
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 24 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.

## [Unreleased]

- N/A
- Replaced kwargs with optional, named keyword arguments

## [1.7.3]

Expand Down
3 changes: 1 addition & 2 deletions sleeper/api/AvatarAPIClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@

class AvatarAPIClient(SleeperAPIClient):
@classmethod
def get_avatar(cls, *, avatar_id: str, save_to_path: str, **kwargs) -> None:
thumbnail = kwargs.pop("thumbnail", False)
def get_avatar(cls, *, avatar_id: str, save_to_path: str, thumbnail: bool = False) -> None:
if thumbnail:
url = cls._build_route(
cls._SLEEPER_CDN_BASE_URL, None, cls._AVATARS_ROUTE, cls._THUMBS_ROUTE, avatar_id
Expand Down
8 changes: 5 additions & 3 deletions sleeper/api/PlayerAPIClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ def get_all_players(cls, *, sport: Sport) -> dict[str, Player]:

@classmethod
def get_trending_players(
cls, *, sport: Sport, trend_type: TrendType, **kwargs
cls, *, sport: Sport, trend_type: TrendType, lookback_hours: int = None, limit: int = None
) -> list[PlayerTrend]:
lookback_hours = kwargs.pop("lookback_hours", cls.__DEFAULT_TRENDING_PLAYERS_LOOKBACK_HOURS)
limit = kwargs.pop("limit", cls.__DEFAULT_TRENDING_PLAYERS_LIMIT)
if lookback_hours is None:
lookback_hours = cls.__DEFAULT_TRENDING_PLAYERS_LOOKBACK_HOURS
if limit is None:
limit = cls.__DEFAULT_TRENDING_PLAYERS_LIMIT
url = cls._build_route(
cls._SLEEPER_APP_BASE_URL,
cls._VERSION,
Expand Down
48 changes: 34 additions & 14 deletions sleeper/api/unofficial/UPlayerAPIClient.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,25 @@
from typing import Any
from typing import Any, Optional

from sleeper.api.SleeperAPIClient import SleeperAPIClient
from sleeper.enum import PlayerPosition, SeasonType
from sleeper.enum import SeasonType
from sleeper.enum.Sport import Sport
from sleeper.model.PlayerStats import PlayerStats


class UPlayerAPIClient(SleeperAPIClient):
@classmethod
def get_player_stats(
cls, *, sport: Sport, player_id: str, season: str, **kwargs
cls,
*,
sport: Sport,
player_id: str,
season: str,
season_type: SeasonType = SeasonType.REGULAR,
week: Optional[int] = None,
) -> PlayerStats:
"""
Gets player stats for the given season OR just the given week.
"""
season_type: SeasonType = kwargs.pop("season_type", SeasonType.REGULAR)
week: int = kwargs.pop("week", None)

url = cls._build_route(
cls._SLEEPER_APP_BASE_URL,
Expand All @@ -40,13 +44,17 @@ def get_player_stats(

@classmethod
def get_player_projections(
cls, *, sport: Sport, player_id: str, season: str, **kwargs
cls,
*,
sport: Sport,
player_id: str,
season: str,
season_type: SeasonType = SeasonType.REGULAR,
week: Optional[int] = None,
) -> PlayerStats:
"""
Gets player projections for the given season OR just the given week.
"""
season_type: SeasonType = kwargs.pop("season_type", SeasonType.REGULAR)
week: int = kwargs.pop("week", None)

url = cls._build_route(
cls._SLEEPER_APP_BASE_URL,
Expand All @@ -71,10 +79,16 @@ def get_player_projections(

@classmethod
def get_all_player_stats(
cls, *, sport: Sport, season: str, week: int, **kwargs
cls,
*,
sport: Sport,
season: str,
week: int,
season_type: SeasonType = SeasonType.REGULAR,
positions: list[str] = None,
) -> list[PlayerStats]:
season_type: SeasonType = kwargs.pop("season_type", SeasonType.REGULAR)
positions: list[PlayerPosition] = kwargs.pop("positions", list())
if positions == None:
positions = []

url = cls._build_route(
cls._SLEEPER_APP_BASE_URL, None, cls._STATS_ROUTE, sport.name.lower(), season, week
Expand All @@ -97,10 +111,16 @@ def get_all_player_stats(

@classmethod
def get_all_player_projections(
cls, *, sport: Sport, season: str, week: int, **kwargs
cls,
*,
sport: Sport,
season: str,
week: int,
season_type: SeasonType = SeasonType.REGULAR,
positions: list[str] = None,
) -> list[PlayerStats]:
season_type: SeasonType = kwargs.pop("season_type", SeasonType.REGULAR)
positions: list[PlayerPosition] = kwargs.pop("positions", list())
if positions == None:
positions = []

url = cls._build_route(
cls._SLEEPER_APP_BASE_URL,
Expand Down
5 changes: 3 additions & 2 deletions sleeper/api/unofficial/USportAPIClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@

class USportAPIClient(SleeperAPIClient):
@classmethod
def get_regular_season_schedule(cls, *, sport: Sport, season: str, **kwargs) -> list[Game]:
season_type: SeasonType = kwargs.pop("season_type", SeasonType.REGULAR)
def get_regular_season_schedule(
cls, *, sport: Sport, season: str, season_type: SeasonType = SeasonType.REGULAR
) -> list[Game]:
url = cls._build_route(
cls._SLEEPER_APP_BASE_URL,
None,
Expand Down
4 changes: 2 additions & 2 deletions test/helper/helper_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@


class MockResponse:
def __init__(self, data: dict | list, status_code: int, **kwargs):
def __init__(self, data: dict | list, status_code: int, content: any = None):
self.__data = data
self.content = kwargs.pop("content", None)
self.content = content
self.status_code = status_code

def json(self):
Expand Down

0 comments on commit 402f354

Please sign in to comment.