maint: improve type annotations · python-validators/validators@7abacca · GitHub
Skip to content

Commit 7abacca

Browse files
committed
maint: improve type annotations
- prefer type inference over explicit typing for function returns - removes unsettling code in comments from `between.py` - uses `local` instead of `project` to refer local imports
1 parent 04bac38 commit 7abacca

5 files changed

Lines changed: 17 additions & 21 deletions

File tree

tests/test_between.py

Lines changed: 5 additions & 6 deletions

validators/_extremes.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class AbsMax:
2828
.. versionadded:: 0.2
2929
"""
3030

31-
def __ge__(self, other: Any) -> bool:
31+
def __ge__(self, other: Any):
3232
"""GreaterThanOrEqual."""
3333
return other is not AbsMax
3434

@@ -55,6 +55,6 @@ class AbsMin:
5555
.. versionadded:: 0.2
5656
"""
5757

58-
def __le__(self, other: Any) -> bool:
58+
def __le__(self, other: Any):
5959
"""LessThanOrEqual."""
6060
return other is not AbsMin

validators/between.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
from typing import TypeVar, Union
66
from datetime import datetime
77

8-
# project
8+
# local
99
from ._extremes import AbsMax, AbsMin
1010
from .utils import validator
1111

@@ -19,7 +19,7 @@ def between(
1919
*,
2020
min_val: Union[T, AbsMin, None] = None,
2121
max_val: Union[T, AbsMax, None] = None,
22-
) -> bool:
22+
):
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
@@ -80,9 +80,6 @@ def between(
8080
if min_val is None:
8181
min_val = AbsMin()
8282

83-
# if isinstance(min_val, AbsMin) and isinstance(max_val, AbsMax):
84-
# return min_val <= value <= max_val
85-
8683
if isinstance(min_val, AbsMin):
8784
if type(value) is not type(max_val):
8885
raise TypeError("`value` and `max_val` must be of same type")

validators/length.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Length."""
22
# -*- coding: utf-8 -*-
33

4-
# project
4+
# local
55
from .between import between
66
from .utils import validator
77

validators/utils.py

Lines changed: 7 additions & 7 deletions

0 commit comments

Comments
 (0)