Skip to content

Commit 7d14778

Browse files
fixed bugs and reformatted files
1 parent 8c8d336 commit 7d14778

7 files changed

Lines changed: 29 additions & 25 deletions

File tree

func_validator/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
from ._func_arg_validator import validate_params
33
from .validators import *
44

5-
__version__ = "1.3.0"
5+
__version__ = "1.3.1"
66
__all__ = ["validate_params"] + validators.__all__

func_validator/validators/_core.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,15 @@ def transform(self, **kwargs):
3636

3737
class Validator(ABC):
3838

39-
def __init__(self, *, err_msg: Optional[str | ErrorMsg] = "") -> None:
40-
if err_msg:
39+
def __init__(self, *, err_msg: str | ErrorMsg = "") -> None:
40+
if isinstance(err_msg, str):
4141
self.err_msg = ErrorMsg(err_msg)
42-
else:
42+
elif isinstance(err_msg, ErrorMsg):
4343
self.err_msg = err_msg
44+
else:
45+
raise ValidationError(
46+
f"err_msg must be str or ErrorMsg, not {type(err_msg)}"
47+
)
4448

4549
@abstractmethod
4650
def __call__(self, *args, **kwargs) -> T: ...

func_validator/validators/collection_arg_validators.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from operator import contains
2-
from typing import Callable, Container, Iterable, Optional, Sized
2+
from typing import Callable, Container, Iterable, Sized
33

44
from ._core import ErrorMsg, Number, T, ValidationError, Validator
55
from .numeric_arg_validators import (
@@ -85,7 +85,7 @@ def __call__(self, arg_value: T, arg_name: str):
8585

8686
class MustBeEmpty(Validator):
8787

88-
def __init__(self, *, err_msg: Optional[str] = None):
88+
def __init__(self, *, err_msg: str = ""):
8989
"""
9090
:param err_msg: Error message.
9191
"""
@@ -102,7 +102,7 @@ def __call__(self, arg_value: Sized, arg_name: str, /):
102102

103103
class MustBeNonEmpty(Validator):
104104

105-
def __init__(self, *, err_msg: Optional[str] = None):
105+
def __init__(self, *, err_msg: str = ""):
106106
"""
107107
:param err_msg: Error message.
108108
"""
@@ -122,7 +122,7 @@ class MustHaveLengthEqual(Validator):
122122
value.
123123
"""
124124

125-
def __init__(self, value: int, *, err_msg: Optional[str] = None):
125+
def __init__(self, value: int, *, err_msg: str = ""):
126126
"""
127127
:param value: The length of the iterable.
128128
:param err_msg: Error message.
@@ -143,7 +143,7 @@ class MustHaveLengthGreaterThan(Validator):
143143
value.
144144
"""
145145

146-
def __init__(self, value: int, *, err_msg: Optional[str] = None):
146+
def __init__(self, value: int, *, err_msg: str = ""):
147147
"""
148148
:param value: The length of the iterable.
149149
:param err_msg: Error message.
@@ -164,7 +164,7 @@ class MustHaveLengthGreaterThanOrEqual(Validator):
164164
the specified value.
165165
"""
166166

167-
def __init__(self, value: int, *, err_msg: Optional[str] = None):
167+
def __init__(self, value: int, *, err_msg: str = ""):
168168
"""
169169
:param value: The length of the iterable.
170170
:param err_msg: Error message
@@ -185,7 +185,7 @@ class MustHaveLengthLessThan(Validator):
185185
value.
186186
"""
187187

188-
def __init__(self, value: int, *, err_msg: Optional[str] = None):
188+
def __init__(self, value: int, *, err_msg: str = ""):
189189
"""
190190
:param value: The length of the iterable.
191191
:param err_msg: Error message.
@@ -206,7 +206,7 @@ class MustHaveLengthLessThanOrEqual(Validator):
206206
the specified value.
207207
"""
208208

209-
def __init__(self, value: int, *, err_msg: Optional[str] = None):
209+
def __init__(self, value: int, *, err_msg: str = ""):
210210
"""
211211
:param value: The length of the iterable.
212212
:param err_msg: Error message.
@@ -234,7 +234,7 @@ def __init__(
234234
max_value: int,
235235
min_inclusive: bool = True,
236236
max_inclusive: bool = True,
237-
err_msg: Optional[str] = None,
237+
err_msg: str = "",
238238
):
239239
"""
240240
:param min_value: The minimum value (inclusive or exclusive based
@@ -276,7 +276,7 @@ class MustHaveValuesGreaterThan(Validator):
276276
specified min_value.
277277
"""
278278

279-
def __init__(self, min_value: Number, *, err_msg: Optional[str] = None):
279+
def __init__(self, min_value: Number, *, err_msg: str = ""):
280280
"""
281281
:param min_value: The minimum value the values in the iterable
282282
should be greater than.
@@ -298,7 +298,7 @@ class MustHaveValuesGreaterThanOrEqual(Validator):
298298
equal to the specified min_value.
299299
"""
300300

301-
def __init__(self, min_value: Number, *, err_msg: Optional[str] = None):
301+
def __init__(self, min_value: Number, *, err_msg: str = ""):
302302
"""
303303
:param min_value: The minimum value the values in the iterable
304304
should be greater than or equal to.
@@ -320,7 +320,7 @@ class MustHaveValuesLessThan(Validator):
320320
specified max_value.
321321
"""
322322

323-
def __init__(self, max_value: Number, *, err_msg: Optional[str] = None):
323+
def __init__(self, max_value: Number, *, err_msg: str = ""):
324324
"""
325325
:param max_value: The maximum value the values in the iterable
326326
should be less than.
@@ -342,7 +342,7 @@ class MustHaveValuesLessThanOrEqual(Validator):
342342
equal to the specified max_value.
343343
"""
344344

345-
def __init__(self, max_value: Number, *, err_msg: Optional[str] = None):
345+
def __init__(self, max_value: Number, *, err_msg: str = ""):
346346
"""
347347
:param max_value: The maximum value the values in the iterable
348348
should be less than or equal to.
@@ -371,7 +371,7 @@ def __init__(
371371
max_value: Number,
372372
min_inclusive: bool = True,
373373
max_inclusive: bool = True,
374-
err_msg: Optional[str] = None,
374+
err_msg: str = "",
375375
):
376376
"""
377377
:param min_value: The minimum value (inclusive or exclusive based

func_validator/validators/datatype_arg_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, Type
1+
from typing import Type
22

33
from ._core import ErrorMsg, T, ValidationError, Validator
44

func_validator/validators/dependent_argument_validator.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Optional, Type
1+
from typing import Type
22

33
from ._core import T, ValidationError, Validator
44
from .numeric_arg_validators import MustBeLessThan, MustBeTruthy
@@ -20,7 +20,7 @@ def __init__(
2020
*args: str,
2121
args_strategy: Type[Validator] = MustBeLessThan,
2222
kw_strategy: Type[Validator] = MustBeTruthy,
23-
err_msg: Optional[str] = "",
23+
err_msg: str = "",
2424
**kwargs: T,
2525
):
2626
"""

func_validator/validators/numeric_arg_validators.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import math
22
from functools import partial
33
from operator import eq, ge, gt, le, lt, ne
4-
from typing import Callable, Optional
4+
from typing import Callable
55

66
from ._core import (
77
OPERATOR_SYMBOLS,
@@ -189,10 +189,10 @@ def __call__(self, arg_value: Number, arg_name: str, /):
189189
# Comparison validation functions
190190

191191

192-
# TODO: Deprecate this and work on logic
192+
# TODO: Deprecate this and work on logic in MustBeProvided
193193
class MustBeTruthy(Validator):
194194

195-
def __init__(self, *, err_msg: str = None) -> None:
195+
def __init__(self, *, err_msg: str = "") -> None:
196196
super().__init__(err_msg=err_msg)
197197

198198
def __call__(self, arg_value: T, arg_name: str):

func_validator/validators/text_arg_validators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import re
2-
from typing import Callable, Literal, Optional
2+
from typing import Callable, Literal
33

44
from ._core import ErrorMsg, T, ValidationError, Validator
55

0 commit comments

Comments
 (0)