Skip to content

v4.0.1

Latest

Choose a tag to compare

@petereon petereon released this 15 Oct 11:58
· 9 commits to master since this release
7c332d4

Breaking changes

  • No more global state (#157): Config is a per-call object, select(..., config=Config(...)), carrying console and keys (DefaultKeys → KeyBindings). Module-level console is removed. Using a removed global raises RemovedInV4Error (or AttributeError when assigning on the Config/KeyBindings class) with a message explaining the replacement.
  • Keyword-only arguments: only the first argument of select, select_multiple, prompt, confirm and Spinner is positional (Spinner(DOTS, text="...")).
  • Ctrl+C raises KeyboardInterrupt by default (Config.raise_on_interrupt=True). It used to return None, so a script carried on as if the user had chosen "nothing". Esc still returns None.
  • strict defaults to True on select/select_multiple (#157): empty options raises ValueError unless strict=False is passed.
  • pagination flag removed. page_size alone now controls paging: None fits the terminal and paginates only when needed, an integer always paginates with that many options per page. Before, page_size was silently ignored unless pagination=True was passed too, and pagination=False could not actually turn paging off.
  • Select-all is ctrl+a instead of a, so a can be typed into a filter. Select-all keeps existing ticks (filling up to maximal_count in list order) and acts on visible options when filtering.
  • Default console no longer highlights (Console(stderr=True, highlight=False)), restoring the 3.8.2 look.
  • Dependencies: emoji is dropped and rich>=14.3.0 is required. Cursor/tick widths now come from rich.cells.cell_len, which matches emoji on every cursor/tick tried and is more accurate for CJK and combining characters, but only measures variation-selector/ZWJ emoji correctly from Rich 14.3 (which still supports Python 3.8).
  • Python: >=3.8 is still declared, but only 3.10+ is tested in CI (noted in the README). The built wheel imports on 3.8, 3.9, 3.10 and 3.14.

New features

  • Title and instructions (#135, discussion #106): title= on select/select_multiple, instructions= on all elements (None hides it).
  • Sectioned options (#74): pass a dict of section name to options. Indices are (section, index) tuples, enforced at runtime and by type checkers via @overload.
  • Filtering (#201): filterable=True narrows options by typed text (case-insensitive, markup ignored), and shows a (matches/total) count next to the query (#157).
  • Input validation, fail loud (#157):
    • A blank option (after preprocessing and stripping markup) or blank section name always raises ValueError naming the entry, e.g. option at ('Veg', 1) is blank, section name '' is blank. Not gated by strict.
    • A bare string as options raises TypeError instead of silently offering its letters.
    • confirm raises on a blank yes_text/no_text (it used to crash with IndexError) and when both labels start with the same letter while the (Y/N) hint is shown.
    • Without an interactive terminal (piped stdin, most CI), every element raises RuntimeError('Interactive terminal required') instead of an opaque termios.error.
  • Spinner is a context manager (with Spinner(...): also stops it if the body raises) and accepts console= so it can share a console with the other elements.
  • Typing: py.typed is now shipped (the wheel had none, so the overloads were invisible to downstream type checkers). prompt(..., target_type=int) is typed Optional[int] and its validator is checked against that type. options accepts any Sequence/Mapping; tuples and ranges already worked at runtime. __all__ and __version__ are declared.
  • Exceptions: ValidationError and ConversionError are now ValueError subclasses. A failed validator can no longer be mistaken for a failed conversion, and a validator that raises ValueError itself is no longer swallowed as one.

Fixes

  • Automatic page size subtracted a hard-coded 6 lines in select but only 1 in select_multiple, so select_multiple rendered taller than the terminal and Rich's Live cropped its page indicator and instructions (confirmed in a real pty). It is now derived from what is actually rendered (title/filter line, page indicator, instructions, the error line when min/max counts can produce one), identically for both, and section headers are bounded by what a page can hold. A property test asserts no render is taller than the terminal across heights, section counts, titles, filtering and error states.
  • prompt() docstring pointed at a nonexistent rich.internals module.

Docs

docs/content/examples.md: rewritten Configuration section, new sections for title/instructions/sections, filtering, pagination, input validation and spinners, and a 3.x → 4.x migration table. The README spinner example uses the context manager.

Tooling & CI

  • Poetry → uv. [tool.poetry] → PEP 621 [project], poetry.lock → uv.lock, build backend poetry-core → uv_build. Releases now build and publish with uv build/uv publish instead of Poetry + pypa/gh-action-pypi-publish.
  • requirements-dev.txt/docs/requirements.txt (hand-pinned, unlocked, installed via two separate untracked pip installs) folded into [dependency-groups] dev/docs, resolved and hash-locked together in uv.lock. Declared as [tool.uv] conflicts since they were never actually installed together (dev's watchdog==6.0.0 vs. novella's watchdog<3.0.0).
  • Dropped dead dependencies never wired into any task or CI step: expycted, mock (tests use stdlib unittest.mock), radon, xenon, toml-sort, perflint, a duplicate pydoc-markdown pin, and types-emoji.
  • flake8 + 10 plugins + black + isort → ruff. ruff check/ruff format replace pflake8, black, isort, and flake8-simplify/-pie/-bandit/-cognitive-complexity/-expression-complexity/-quotes/-print/-eradicate. Fixed the 8 real findings ruff's rules turned up that flake8's narrower select list and dead plugins never caught.
  • mypy kept (ruff doesn't type-check).
  • CodeQL and dependency-review workflows removed. SonarCloud kept. The relock-with-autocommit job replaced with a plain uv lock --check.
  • Two third-party GitHub Actions pinned to commit SHAs (astral-sh/setup-uv, JamesIves/github-pages-deploy-action), flagged by Sonar as a high-severity supply-chain risk (tag refs are mutable).
  • docs group needs uv pip install --group docs rather than uv sync: novella's pkg_resources-based plugin loader can't resolve uv's dist-info metadata for dotted distribution names (e.g. databind.json). Also needs setuptools<81 (pkg_resources was removed in 81+).