Skip to content

Commit

Permalink
Fixes to fringe cases when gameweek passed as 0
Browse files Browse the repository at this point in the history
Setting `gameweek` parameter to `0` should throw a `ValueError`.

Some User functions currently evaluate `if gameweek:` to check for the presence of a specified `gameweek`.
As `if 0:` evaluates to `False` it is treated the same as the default parameter `None`.

Correcting them to be `if gameweek is not None:` which correctly throws `ValueError`.
  • Loading branch information
Ridingst authored Oct 9, 2019
1 parent cfe612e commit 7bd0360
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions fpl/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ async def get_gameweek_history(self, gameweek=None):

self._history = history

if gameweek:
if gameweek is not None:
valid_gameweek(gameweek)
return next(gw for gw in history["current"]
if gw["event"] == gameweek)
Expand Down Expand Up @@ -183,7 +183,7 @@ async def get_chips_history(self, gameweek=None):

self._history = history

if gameweek:
if gameweek is not None:
valid_gameweek(gameweek)
try:
return next(chip for chip in history["chips"]
Expand Down Expand Up @@ -253,7 +253,7 @@ async def get_active_chips(self, gameweek=None):
picks = await asyncio.gather(*tasks)
self._picks = picks

if gameweek:
if gameweek is not None:
valid_gameweek(gameweek)
try:
return [next(pick["active_chip"] for pick in picks
Expand Down Expand Up @@ -283,7 +283,7 @@ async def get_automatic_substitutions(self, gameweek=None):
picks = await asyncio.gather(*tasks)
self._picks = picks

if gameweek:
if gameweek is not None:
valid_gameweek(gameweek)
try:
return next(pick["automatic_subs"] for pick in picks
Expand Down Expand Up @@ -329,7 +329,7 @@ async def get_transfers(self, gameweek=None):
self._session, API_URLS["user_transfers"].format(self.id))
self._transfers = transfers

if gameweek:
if gameweek is not None:
valid_gameweek(gameweek)
return [transfer for transfer in transfers
if transfer["event"] == gameweek]
Expand Down

0 comments on commit 7bd0360

Please sign in to comment.