Skip to content

Commit 034e970

Browse files
committed
feat: formats google pydoc style for mkdocstring
1 parent a68ff9a commit 034e970

File tree

5 files changed

+72
-97
lines changed

5 files changed

+72
-97
lines changed

validators/_extremes.py

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,19 @@
1010
class AbsMax:
1111
"""An object that is greater than any other object (except itself).
1212
13-
Inspired by https://pypi.python.org/pypi/Extremes
14-
15-
Examples::
16-
17-
>>> import sys
13+
Inspired by https://pypi.python.org/pypi/Extremes.
1814
15+
Examples:
16+
>>> from sys import maxint
1917
>>> AbsMax > AbsMin
20-
True
21-
22-
>>> AbsMax > sys.maxint
23-
True
24-
18+
# Output: True
19+
>>> AbsMax > maxint
20+
# Output: True
2521
>>> AbsMax > 99999999999999999
26-
True
22+
# Output: True
2723
28-
.. versionadded:: 0.2
24+
Note:
25+
- New in version 0.2.
2926
"""
3027

3128
def __ge__(self, other: Any):
@@ -37,22 +34,19 @@ def __ge__(self, other: Any):
3734
class AbsMin:
3835
"""An object that is less than any other object (except itself).
3936
40-
Inspired by https://pypi.python.org/pypi/Extremes
41-
42-
Examples::
43-
44-
>>> import sys
45-
46-
>>> AbsMin < -sys.maxint
47-
True
37+
Inspired by https://pypi.python.org/pypi/Extremes.
4838
39+
Examples:
40+
>>> from sys import maxint
41+
>>> AbsMin < -maxint
42+
# Output: True
4943
>>> AbsMin < None
50-
True
51-
44+
# Output: True
5245
>>> AbsMin < ''
53-
True
46+
# Output: True
5447
55-
.. versionadded:: 0.2
48+
Note:
49+
- New in version 0.2.
5650
"""
5751

5852
def __le__(self, other: Any):

validators/between.py

Lines changed: 26 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -9,68 +9,63 @@
99
from ._extremes import AbsMax, AbsMin
1010
from .utils import validator
1111

12-
T = TypeVar("T", int, float, str, datetime)
12+
PossibleValueTypes = TypeVar("PossibleValueTypes", int, float, str, datetime)
1313

1414

1515
@validator
1616
def between(
17-
value: T,
17+
value: PossibleValueTypes,
1818
/,
1919
*,
20-
min_val: Union[T, AbsMin, None] = None,
21-
max_val: Union[T, AbsMax, None] = None,
20+
min_val: Union[PossibleValueTypes, AbsMin, None] = None,
21+
max_val: Union[PossibleValueTypes, AbsMax, None] = None,
2222
):
2323
"""Validate that a number is between minimum and/or maximum value.
2424
2525
This will work with any comparable type, such as floats, decimals and dates
26-
not just integers. This validator is originally based on `WTForms-NumberRange-Validator`_
26+
not just integers. This validator is originally based on [WTForms-NumberRange-Validator][1].
2727
28-
.. _WTForms-NumberRange-Validator:
29-
https://github.com/wtforms/wtforms/blob/master/src/wtforms/validators.py#L166-L220
30-
31-
Examples::
28+
[1]: https://github.com/wtforms/wtforms/blob/master/src/wtforms/validators.py#L166-L220
3229
30+
Examples:
3331
>>> from datetime import datetime
34-
3532
>>> between(5, min_val=2)
3633
# Output: True
37-
3834
>>> between(13.2, min_val=13, max_val=14)
3935
# Output: True
40-
4136
>>> between(500, max_val=400)
4237
# Output: ValidationFailure(func=between, args=...)
43-
4438
>>> between(
4539
... datetime(2000, 11, 11),
4640
... min_val=datetime(1999, 11, 11)
4741
... )
48-
# True
42+
# Output: True
4943
5044
Args:
51-
`value`:
52-
[Required] Value which is to be compared.
53-
`min_val`:
54-
[Optional] The minimum required value of the number.
45+
value:
46+
Value which is to be compared.
47+
min_val:
48+
The minimum required value of the number.
5549
If not provided, minimum value will not be checked.
56-
`max_val`:
57-
[Optional] The maximum value of the number.
50+
max_val:
51+
The maximum value of the number.
5852
If not provided, maximum value will not be checked.
59-
Either one of `min_val` or `max_val` must be provided.
6053
6154
Returns:
62-
A `boolean` if `value` is greater than `min_val` and
63-
less than `max_val`.
55+
(Literal[True]):
56+
If `value` is in between the given conditions.
57+
(ValidationFailure):
58+
If `value` is not in between the given conditions.
6459
6560
Raises:
66-
`AssertionError`:
67-
- If both `min_val` and `max_val` are `None`.
68-
- If `min_val` is greater than `max_val`.
69-
70-
`TypeError`:
71-
- If there's a type mismatch before comparison
72-
73-
.. versionadded:: 0.2
61+
AssertionError: If both `min_val` and `max_val` are `None`,
62+
or if `min_val` is greater than `max_val`.
63+
TypeError: If there's a type mismatch before comparison.
64+
65+
Note:
66+
- `PossibleValueTypes` = `TypeVar("PossibleValueTypes", int, float, str, datetime)`
67+
- Either one of `min_val` or `max_val` must be provided.
68+
- New in version 0.2.
7469
"""
7570
if min_val is None and max_val is None:
7671
raise AssertionError("At least one of either `min_val` or `max_val` must be specified")

validators/btc_address.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,21 @@ def btc_address(value: str, /):
3434
For segwit addresses a regexp is used to provide a reasonable
3535
estimate on whether the address is valid.
3636
37-
Examples::
38-
37+
Examples:
3938
>>> btc_address('3Cwgr2g7vsi1bXDUkpEnVoRLA9w4FZfC69')
4039
# Output: True
4140
>>> btc_address('1BvBMsEYstWetqTFn5Au4m4GFg7xJaNVN2')
4241
# Output: ValidationFailure(func=btc_address, args=...)
4342
4443
Args:
45-
`value`:
46-
[Required] Bitcoin address string to validate.
44+
value:
45+
Bitcoin address string to validate.
4746
4847
Returns:
49-
`True`:
50-
If the value is valid bitcoin address.
51-
`ValidationFailure`:
52-
If the value is an invalid bitcoin address.
53-
48+
(Literal[True]):
49+
If `value` is a valid bitcoin address.
50+
(ValidationFailure):
51+
If `value` is an invalid bitcoin address.
5452
"""
5553
if value and type(value) is str:
5654
return (

validators/length.py

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,31 @@
1010
def length(value: str, /, *, min_val: int = 0, max_val: int = 0):
1111
"""Return whether or not the length of given string is within a specified range.
1212
13-
Examples::
14-
13+
Examples:
1514
>>> length('something', min_val=2)
1615
# Output: True
17-
1816
>>> length('something', min_val=9, max_val=9)
1917
# Output: True
20-
2118
>>> length('something', max_val=5)
2219
# Output: ValidationFailure(func=length, ...)
2320
2421
Args:
25-
`value`:
26-
[Required] The string to validate.
27-
`min_val`:
28-
[Optional] The minimum required length of the string. If not provided,
22+
value:
23+
The string to validate.
24+
min_val:
25+
The minimum required length of the string. If not provided,
2926
minimum length will not be checked.
30-
`max_val`:
31-
[Optional] The maximum length of the string. If not provided,
27+
max_val:
28+
The maximum length of the string. If not provided,
3229
maximum length will not be checked.
33-
Either one of `min_val` or `max_val` must be provided.
3430
3531
Returns:
36-
A `boolean` if `value` is greater than `min_val` and
37-
less than `max_val`.
32+
(Literal[True]):
33+
If `len(value)` is in between the given conditions.
34+
(ValidationFailure):
35+
If `len(value)` is not in between the given conditions.
3836
39-
.. versionadded:: 0.2
37+
Note:
38+
- New in version 0.2.
4039
"""
4140
return between(len(value), min_val=min_val, max_val=max_val)

validators/utils.py

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def __bool__(self):
3333

3434
def _func_args_as_dict(func: Callable[..., Any], *args: Any, **kwargs: Any):
3535
"""Return function's positional and key value arguments as an ordered dictionary."""
36-
# TODO: find more efficient way to do it
3736
return dict(
3837
list(zip(dict.fromkeys(chain(getfullargspec(func)[0], kwargs.keys())), args))
3938
+ list(kwargs.items())
@@ -43,26 +42,26 @@ def _func_args_as_dict(func: Callable[..., Any], *args: Any, **kwargs: Any):
4342
def validator(func: Callable[..., Any]):
4443
"""A decorator that makes given function validator.
4544
46-
Whenever the given function is called and returns ``False`` value
47-
this decorator returns :class:`ValidationFailure` object.
48-
49-
Example::
45+
Whenever the given `func` returns `False` this
46+
decorator returns `ValidationFailure` object.
5047
48+
Examples:
5149
>>> @validator
5250
... def even(value):
5351
... return not (value % 2)
54-
5552
>>> even(4)
5653
# Output: True
57-
5854
>>> even(5)
5955
# Output: ValidationFailure(func=even, args={'value': 5})
6056
6157
Args:
62-
`func`: function which is to be decorated.
58+
func:
59+
Function which is to be decorated.
6360
6461
Returns:
65-
Wrapper function as a decorator.
62+
(Callable[..., ValidationFailure | Literal[True])):
63+
A decorator which returns either `ValidationFailure`
64+
or `Literal[True]`.
6665
"""
6766

6867
def wrapper(*args: Any, **kwargs: Any):
@@ -71,15 +70,5 @@ def wrapper(*args: Any, **kwargs: Any):
7170
if func(*args, **kwargs)
7271
else ValidationFailure(func, _func_args_as_dict(func, *args, **kwargs))
7372
)
74-
# try:
75-
# return (
76-
# True
77-
# if func(*args, **kwargs)
78-
# else ValidationFailure(func, _func_args_as_dict(func, *args, **kwargs))
79-
# )
80-
# except (AssertionError, TypeError) as err:
81-
# print(err)
82-
# finally:
83-
# return ValidationFailure(func, _func_args_as_dict(func, *args, **kwargs))
8473

8574
return wrapper

0 commit comments

Comments
 (0)