Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/yt-dlp/yt-dlp into ytdlp
Browse files Browse the repository at this point in the history
* 'master' of https://github.com/yt-dlp/yt-dlp:
  [utils] Fix `PagedList`
  • Loading branch information
Lesmiscore committed Nov 16, 2021
2 parents 650e271 + d8cf8d9 commit 517c89a
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions yt_dlp/utils.py
Expand Up @@ -2658,7 +2658,9 @@ def __init__(self, pagefunc, pagesize, use_cache=True):
self._cache = {}

def getpage(self, pagenum):
page_results = self._cache.get(pagenum) or list(self._pagefunc(pagenum))
page_results = self._cache.get(pagenum)
if page_results is None:
page_results = list(self._pagefunc(pagenum))
if self._use_cache:
self._cache[pagenum] = page_results
return page_results
Expand All @@ -2674,7 +2676,9 @@ def __getitem__(self, idx):
if not isinstance(idx, int) or idx < 0:
raise TypeError('indices must be non-negative integers')
entries = self.getslice(idx, idx + 1)
return entries[0] if entries else None
if not entries:
raise IndexError()
return entries[0]


class OnDemandPagedList(PagedList):
Expand Down

0 comments on commit 517c89a

Please sign in to comment.