fix: cache=[] disables the button (not raises); nav row stays suppressed on re-render (v0.1.4)

M-3: the cache-length guard used 'cache is not None', so cache=[] ([] is not None) hit the
length check and raised at construction — contradicting README/CLAUDE that say a falsy
cache disables the button (matching the render path 'if self.cache:'). guard now uses
'if cache' so [] and None both disable; a non-empty too-short cache still raises.

dpy_paginator-F2: update_buttons() now ANDs nav with max_pages>=2, so a single-page
re-render (update_page -> _build_render_kwargs, default nav=True) no longer resurrects the
nav row over the page's custom buttons. start()'s single-page branch simplified accordingly.

verified by execution with real discord.py: []-disables and None-disables both construct,
real cache renders, too-short still raises; single-page re-render keeps nav suppressed +
custom button, multi-page control still shows nav.

Signed-off-by: disqualifier <dev@disqualifier.me>
This commit is contained in:
disqualifier 2026-06-29 20:47:43 -04:00
parent de572af675
commit 1416375e40
3 changed files with 18 additions and 14 deletions

View File

@ -9,18 +9,18 @@ buttons) behind previous / jump / next navigation, with an optional cache button
`requirements.txt`: `requirements.txt`:
``` ```
dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.3 dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.4
``` ```
Direct: Direct:
```bash ```bash
pip install "dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.3" pip install "dpy_paginator @ git+ssh://git@git.rethinkstudios.io/rethink-public/dpy_paginator.git@v0.1.4"
``` ```
Requires `discord.py` (pulled transitively). Requires `discord.py` (pulled transitively).
Drop the `@v0.1.3` suffix from the line above to install the latest unpinned. Drop the `@v0.1.4` suffix from the line above to install the latest unpinned.
## Basic usage ## Basic usage

View File

@ -4,7 +4,7 @@ build-backend = "hatchling.build"
[project] [project]
name = "dpy_paginator" name = "dpy_paginator"
version = "0.1.3" version = "0.1.4"
description = "Button-navigated paginator for discord.py — config-free, injectable emojis, installable." description = "Button-navigated paginator for discord.py — config-free, injectable emojis, installable."
requires-python = ">=3.10" requires-python = ">=3.10"
dependencies = [ dependencies = [

View File

@ -176,7 +176,9 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
total_pages, left_over = divmod(len(self.pages), self.per_page) total_pages, left_over = divmod(len(self.pages), self.per_page)
self.max_pages: int = total_pages + (1 if left_over else 0) self.max_pages: int = total_pages + (1 if left_over else 0)
if cache is not None and len(cache) < self.max_pages: # a falsy cache (None or []) disables the cache button (see the render path's
# `if self.cache:`); only a non-empty cache must have one entry per page
if cache and len(cache) < self.max_pages:
raise ValueError( raise ValueError(
f"cache has {len(cache)} entries but there are {self.max_pages} pages; " f"cache has {len(cache)} entries but there are {self.max_pages} pages; "
"cache needs one entry per page" "cache needs one entry per page"
@ -294,9 +296,13 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
nav=False rebuilds with only the page's custom buttons and no navigation nav=False rebuilds with only the page's custom buttons and no navigation
items (prev/jump/cache/next) a single-page result that still carries items (prev/jump/cache/next) a single-page result that still carries
custom buttons keeps them (and their live callbacks) without a nav row. custom buttons keeps them (and their live callbacks) without a nav row.
the nav row is also suppressed for a single page (max_pages < 2) even when
nav is left at its default, so a re-render (update_page) never resurrects it.
""" """
self.clear_items() self.clear_items()
nav = nav and self.max_pages >= 2
if nav: if nav:
self.previous_page.emoji = self.emojis["previous"] self.previous_page.emoji = self.emojis["previous"]
self.previous_page.disabled = self.current_page <= 0 self.previous_page.disabled = self.current_page <= 0
@ -382,15 +388,13 @@ class ButtonPaginator(Generic[PageT_co], discord.ui.View):
) -> Optional[Union[discord.Message, discord.WebhookMessage]]: ) -> Optional[Union[discord.Message, discord.WebhookMessage]]:
"""send the first page; obj is an Interaction or a Messageable""" """send the first page; obj is an Interaction or a Messageable"""
kwargs = await self.get_page_kwargs(self.get_page(self.current_page)) kwargs = await self.get_page_kwargs(self.get_page(self.current_page))
# update_buttons already suppresses the nav row for a single page (max_pages < 2),
# keeping only the page's custom buttons — so a single page with custom buttons
# renders them (live callbacks) with no nav row
self.update_buttons() self.update_buttons()
if self.max_pages < 2: if self.max_pages < 2 and not self.current_page_buttons:
if self.current_page_buttons: # single page, no custom buttons: no interactive row at all, drop the view
# single page WITH custom buttons: keep the view live so the
# buttons' callbacks still fire; strip only the navigation row
self.update_buttons(nav=False)
else:
# single page, no custom buttons: no interactive row at all
self.stop() self.stop()
kwargs.pop("view", None) kwargs.pop("view", None)