1
0
mirror of https://github.com/yt-dlp/yt-dlp.git synced 2024-11-05 18:52:48 +01:00

[utils] Fix PagedList

This commit is contained in:
pukkandan 2021-11-16 21:14:02 +05:30
parent d0d012d4e7
commit d8cf8d97a8
No known key found for this signature in database
GPG Key ID: 0F00D95A001F4698

View File

@ -4179,7 +4179,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
@ -4195,7 +4197,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):