Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for multiple names to Check.register #31

Merged
merged 4 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions src/pyoload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,16 +103,19 @@ def register(cls: Any, name: str) -> Any:
:param cls: the Check class
:param name: the name to be registerred as
"""
if name in cls.checks_list:
raise Check.CheckNameAlreadyExistsError(name)
names = [x for x in name.split(' ') if x.strip() != '']
for name in names:
if name in cls.checks_list:
raise Check.CheckNameAlreadyExistsError(name)

def inner(func: Callable) -> Callable:
"""def inner(func: Callable)
:param func: The callable to register

:returns: func
"""
cls.checks_list[name] = func
for name in names:
cls.checks_list[name] = func
return func
return inner

Expand Down Expand Up @@ -218,7 +221,7 @@ class Checks(PyoloadAnnotation):

def __init__(
self: PyoloadAnnotation,
**checks: dict[str, Callable[Any, Any]]
**checks: dict[str, Callable[Any, Any]],
):
"""def __init__(self: PyoloadAnnotation, **checks)
crates the check object,e.g
Expand Down Expand Up @@ -557,7 +560,7 @@ def overload(func: Callable, name: str | None = None):
__overloads__[name] = []
__overloads__[name].append(annotate(func, True))

@wraps(func: Callable)
@wraps(func)
def wrapper(*args, **kw):
for f in __overloads__[name]:
try:
Expand Down
2 changes: 1 addition & 1 deletion src/tests/test_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from pyoload import annotate
from pyoload import typeMatch

assert pyoload.__version__ == '1.1.2'
assert pyoload.__version__ == '1.1.3'


@annotate
Expand Down
9 changes: 8 additions & 1 deletion src/tests/test_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
from pyoload import Any
from pyoload import CheckedAttr
from pyoload import Checks
from pyoload import Check
from pyoload import annotate

assert pyoload.__version__ == '1.1.2'
assert pyoload.__version__ == '1.1.3'


@annotate
Expand Down Expand Up @@ -35,6 +36,12 @@ def test_check():
else:
raise Exception()

@Check.register('test1 test2')
def test(param, val):
print(param, val)
Checks(test1=3)(3)
Checks(test2=4)(4)


if __name__ == '__main__':
test_check()
2 changes: 1 addition & 1 deletion src/tests/test_overload.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from pyoload import get_name
from pyoload import overload

assert pyoload.__version__ == '1.1.2'
assert pyoload.__version__ == '1.1.3'


@overload
Expand Down
Loading