From 61ff92953217fa5c706b3c5b0142b973557a6ccc Mon Sep 17 00:00:00 2001 From: David Fokkema Date: Sun, 10 Aug 2025 12:31:17 +0200 Subject: [PATCH] SelectType must be Hashable Because of the internal use of a set for `_legal_values`, only hashable options are allowed. --- CHANGELOG.md | 6 ++++++ src/textual/widgets/_select.py | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c5cb4c6a8e..8ed378966f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +# [Unreleased] + +### Fixed + +- Fix type hint for SelectType: only hashable types are allowed. + # [5.3.0] - 2025-08-07 ### Added diff --git a/src/textual/widgets/_select.py b/src/textual/widgets/_select.py index ac7dac6ee5..1926e5a530 100644 --- a/src/textual/widgets/_select.py +++ b/src/textual/widgets/_select.py @@ -1,7 +1,7 @@ from __future__ import annotations from dataclasses import dataclass -from typing import TYPE_CHECKING, Generic, Iterable, TypeVar, Union +from typing import TYPE_CHECKING, Generic, Hashable, Iterable, TypeVar, Union import rich.repr from rich.console import RenderableType @@ -261,7 +261,7 @@ def _on_click(self, event: events.Click) -> None: self.post_message(self.Toggle()) -SelectType = TypeVar("SelectType") +SelectType = TypeVar("SelectType", bound=Hashable) """The type used for data in the Select.""" SelectOption: TypeAlias = "tuple[str, SelectType]" """The type used for options in the Select."""