Skip to content

Commit

Permalink
Input validators crash fix (#4868)
Browse files Browse the repository at this point in the history
* Fix crash when using validate_on with list

* Ensure tests cover crash scenario of validate_on not being a set

* Update CHANGELOG
  • Loading branch information
darrenburns authored Aug 11, 2024
1 parent c39641e commit 3de42a9
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/textual/widgets/_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
7 changes: 4 additions & 3 deletions tests/input/test_input_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 3de42a9

Please sign in to comment.