-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Added type annotation to all public methods * Added 3,5 & 3.10 compatibility
- Loading branch information
Showing
16 changed files
with
96 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
# A Python "namespace package" http://www.python.org/dev/peps/pep-0382/ | ||
# This always goes inside of a namespace package's __init__.py | ||
# This always goes inside a namespace package's __init__.py | ||
|
||
from pkgutil import extend_path | ||
__path__ = extend_path(__path__, __name__) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
from busypie.func import is_async | ||
from busypie.types import ConditionEvaluator | ||
|
||
|
||
async def check(f): | ||
if is_async(f): | ||
return await f() | ||
return f() | ||
async def check(condition_evaluator: ConditionEvaluator) -> any: | ||
if is_async(condition_evaluator): | ||
return await condition_evaluator() | ||
return condition_evaluator() | ||
|
||
|
||
async def negative_check(f): | ||
if is_async(f): | ||
result = await f() | ||
async def negative_check(condition_evaluator: ConditionEvaluator) -> bool: | ||
if is_async(condition_evaluator): | ||
result = await condition_evaluator() | ||
return not result | ||
return not f() | ||
return not condition_evaluator() | ||
|
||
|
||
async def assert_check(f): | ||
if is_async(f): | ||
await f() | ||
async def assert_check(condition_evaluator: ConditionEvaluator) -> bool: | ||
if is_async(condition_evaluator): | ||
await condition_evaluator() | ||
else: | ||
f() | ||
condition_evaluator() | ||
return True |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
import inspect | ||
import re | ||
from functools import partial | ||
from typing import Callable | ||
|
||
|
||
def is_async(func): | ||
def is_async(func) -> bool: | ||
return inspect.iscoroutinefunction(_unpartial(func)) | ||
|
||
|
||
def _unpartial(func): | ||
def _unpartial(func: Callable) -> Callable: | ||
while isinstance(func, partial): | ||
func = func.func | ||
return func | ||
|
||
|
||
def describe(func): | ||
def describe(func: Callable) -> str: | ||
if _is_a_lambda(func): | ||
return _content_of(func) | ||
return _unpartial(func).__name__ | ||
|
||
|
||
def _is_a_lambda(func): | ||
def _is_a_lambda(func: Callable) -> bool: | ||
lambda_template = lambda: 0 # noqa: E731 | ||
return isinstance(func, type(lambda_template)) and \ | ||
func.__name__ == lambda_template.__name__ | ||
|
||
|
||
def _content_of(lambda_func): | ||
def _content_of(lambda_func: Callable) -> str: | ||
source_line = inspect.getsource(lambda_func) | ||
r = re.search(r'lambda[^:]*:\s*(.+)\s*\)', source_line) | ||
return r.group(1) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,19 @@ | ||
from numbers import Number | ||
from typing import Callable | ||
|
||
from busypie.durations import SECOND | ||
|
||
|
||
def time_value_operator(value, unit=SECOND, visitor=None): | ||
def time_value_operator(value: float, unit: float = SECOND, visitor: Callable[[float], any] = None) -> any: | ||
_validate_time_and_unit(value, unit) | ||
return visitor(value * unit) | ||
|
||
|
||
def _validate_time_and_unit(value, unit): | ||
def _validate_time_and_unit(value: float, unit: float) -> None: | ||
_validate_positive_number(value, 'Time value of {} is not allowed') | ||
_validate_positive_number(unit, 'Unit value of {} is not allowed') | ||
|
||
|
||
def _validate_positive_number(value, message): | ||
def _validate_positive_number(value: float, message: str) -> None: | ||
if value is None or not isinstance(value, Number) or value < 0: | ||
raise ValueError(message.format(value)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from typing import Callable | ||
|
||
ConditionEvaluator = Callable[[], any] | ||
|
||
Checker = Callable[[ConditionEvaluator], any] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters