Skip to content

Commit

Permalink
fix #156 allowing objects with no items to return an empty list
Browse files Browse the repository at this point in the history
  • Loading branch information
meisnate12 committed Feb 23, 2024
1 parent 22cfff8 commit 66fb9ba
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.6
1.2.7
4 changes: 3 additions & 1 deletion tmdbapis/objs/pagination.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,12 @@ def get_results(self, amount: Optional[int] = None):
Raises:
:class:`~tmdbapis.exceptions.Invalid`: When ``amount`` is not greater than zero.
"""
if self.total_results == 0:
return []
if amount is None or int(amount) > self.total_results:
amount = self.total_results
if amount < 1:
raise Invalid("amount must be greater then 0")
raise Invalid("amount must be greater than 0")
results = []
current_page = 0
while len(results) < amount and current_page < self.total_pages:
Expand Down
4 changes: 2 additions & 2 deletions tmdbapis/tmdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,11 @@ def _validate_discover(self, is_movie, **kwargs):
elif k in ["primary_release_year", "first_air_date_year", "vote_count.gte", "vote_count.lte",
"with_runtime.gte", "with_runtime.lte"]:
if not isinstance(v, int) or v <= 0:
raise Invalid(f"{k} must be an integer greater then 0")
raise Invalid(f"{k} must be an integer greater than 0")
validated[k] = v
elif k in ["vote_average.gte", "vote_average.lte"]:
if not isinstance(v, (int, float)) or v <= 0:
raise Invalid(f"{k} must be a number greater then 0.0")
raise Invalid(f"{k} must be a number greater than 0.0")
validated[k] = float(v)
elif k == "with_watch_monetization_types":
if v not in ["flatrate", "free", "ads", "rent", "buy"]:
Expand Down

0 comments on commit 66fb9ba

Please sign in to comment.