Skip to content

Commit

Permalink
update Number and Integer validators
Browse files Browse the repository at this point in the history
  • Loading branch information
merriam committed Jul 21, 2024
1 parent 2cabef7 commit f9585f6
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/textual/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ def validate(self, value: str) -> ValidationResult:
except ValueError:
return ValidationResult.failure([Number.NotANumber(self, value)])

if float_value in {math.nan, math.inf, -math.inf}:
if math.isnan(float_value) or math.isinf(float_value):
return ValidationResult.failure([Number.NotANumber(self, value)])

if not self._validate_range(float_value):
Expand Down Expand Up @@ -354,10 +354,10 @@ def validate(self, value: str) -> ValidationResult:
return number_validation_result

# We know it's a number, but is that number an integer?
is_integer = float(value).is_integer()
if not is_integer:
try:
int_value = int(value)
except ValueError:
return ValidationResult.failure([Integer.NotAnInteger(self, value)])

return self.success()

def describe_failure(self, failure: Failure) -> str | None:
Expand Down

0 comments on commit f9585f6

Please sign in to comment.