From 3de42a978a9abf014ee4b00b2492d8ee5fb6fd2d Mon Sep 17 00:00:00 2001 From: Darren Burns Date: Sun, 11 Aug 2024 21:16:22 +0100 Subject: [PATCH] Input validators crash fix (#4868) * Fix crash when using validate_on with list * Ensure tests cover crash scenario of validate_on not being a set * Update CHANGELOG --- CHANGELOG.md | 4 ++++ src/textual/widgets/_input.py | 4 ++-- tests/input/test_input_validation.py | 7 ++++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45262df670..a1d89d071c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Added `tooltip` to Binding https://github.com/Textualize/textual/pull/4859 +### Fixed + +- Fix crash when `validate_on` value isn't a set https://github.com/Textualize/textual/pull/4868 + ## [0.76.0] ### Changed diff --git a/src/textual/widgets/_input.py b/src/textual/widgets/_input.py index 77ec211584..67743b94aa 100644 --- a/src/textual/widgets/_input.py +++ b/src/textual/widgets/_input.py @@ -2,7 +2,7 @@ import re from dataclasses import dataclass -from typing import TYPE_CHECKING, ClassVar, Iterable, cast +from typing import TYPE_CHECKING, ClassVar, Iterable from rich.cells import cell_len, get_character_cell_size from rich.console import Console, ConsoleOptions, RenderableType @@ -301,7 +301,7 @@ def __init__( self.validators = list(validators) self.validate_on: set[str] = ( - (_POSSIBLE_VALIDATE_ON_VALUES & cast("set[str]", validate_on)) + (_POSSIBLE_VALIDATE_ON_VALUES & set(validate_on)) if validate_on is not None else _POSSIBLE_VALIDATE_ON_VALUES ) diff --git a/tests/input/test_input_validation.py b/tests/input/test_input_validation.py index 0f70a98df8..3ea17191b5 100644 --- a/tests/input/test_input_validation.py +++ b/tests/input/test_input_validation.py @@ -100,10 +100,11 @@ async def test_on_blur_triggers_validation(): "validate_on", [ set(), + [], {"blur"}, - {"submitted"}, - {"blur", "submitted"}, - {"fried", "garbage"}, + ["submitted"], + ["blur", "submitted"], + ["fried", "garbage"], ], ) async def test_validation_on_changed_should_not_happen(validate_on):