diff --git a/CHANGELOG.md b/CHANGELOG.md index 6df2d6c3da..6327789eeb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). ### Fixed +- Fixed `Integer` validator missing failure description when not a number https://github.com/Textualize/textual/issues/4413 - Fixed a crash in `DataTable` if you clicked a link in the border https://github.com/Textualize/textual/issues/4410 ### Added diff --git a/src/textual/validation.py b/src/textual/validation.py index bc490829cf..4128c360d2 100644 --- a/src/textual/validation.py +++ b/src/textual/validation.py @@ -363,7 +363,7 @@ def describe_failure(self, failure: Failure) -> str | None: Returns: A string description of the failure. """ - if isinstance(failure, Integer.NotAnInteger): + if isinstance(failure, (Integer.NotANumber, Integer.NotAnInteger)): return "Must be a valid integer." elif isinstance(failure, Integer.NotInRange): if self.minimum is None and self.maximum is not None: diff --git a/tests/test_validation.py b/tests/test_validation.py index 7fccddfb97..c72a64472e 100644 --- a/tests/test_validation.py +++ b/tests/test_validation.py @@ -214,3 +214,11 @@ def test_Function_validate(function, failure_description, is_valid): assert result.is_valid is is_valid if result.failure_descriptions: assert result.failure_descriptions[0] == failure_description + + +def test_Integer_failure_description_when_NotANumber(): + """Regression test for https://github.com/Textualize/textual/issues/4413""" + validator = Integer() + result = validator.validate("x") + assert result.is_valid is False + assert result.failure_descriptions[0] == "Must be a valid integer."