Skip to content

Commit

Permalink
Improve validator typing to allow non-number formats for min and max (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p authored Jun 25, 2024
1 parent ca4006a commit 65f736c
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions voluptuous/validators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# fmt: off
from __future__ import annotations

import datetime
import os
import re
Expand All @@ -18,6 +20,9 @@
# F401: flake8 complains about 'raises' not being used, but it is used in doctests
from voluptuous.schema_builder import Schema, Schemable, message, raises # noqa: F401

if typing.TYPE_CHECKING:
from _typeshed import SupportsAllComparisons

# fmt: on


Expand Down Expand Up @@ -610,9 +615,6 @@ def Maybe(validator: typing.Callable, msg: typing.Optional[str] = None):
return Any(None, validator, msg=msg)


NullableNumber = typing.Union[int, float, None]


class Range(object):
"""Limit a value to a range.
Expand All @@ -636,8 +638,8 @@ class Range(object):

def __init__(
self,
min: NullableNumber = None,
max: NullableNumber = None,
min: SupportsAllComparisons | None = None,
max: SupportsAllComparisons | None = None,
min_included: bool = True,
max_included: bool = True,
msg: typing.Optional[str] = None,
Expand Down Expand Up @@ -705,8 +707,8 @@ class Clamp(object):

def __init__(
self,
min: NullableNumber = None,
max: NullableNumber = None,
min: SupportsAllComparisons | None = None,
max: SupportsAllComparisons | None = None,
msg: typing.Optional[str] = None,
) -> None:
self.min = min
Expand Down Expand Up @@ -736,8 +738,8 @@ class Length(object):

def __init__(
self,
min: NullableNumber = None,
max: NullableNumber = None,
min: SupportsAllComparisons | None = None,
max: SupportsAllComparisons | None = None,
msg: typing.Optional[str] = None,
) -> None:
self.min = min
Expand Down

0 comments on commit 65f736c

Please sign in to comment.