Skip to content

Commit

Permalink
Merge pull request #31 from ken-morel/ken-morel-patch-1
Browse files Browse the repository at this point in the history
Added support for multiple names to Check.register
  • Loading branch information
ken-morel committed Jun 2, 2024
2 parents e4bbd81 + aa58efb commit 8a1e291
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 8 deletions.
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

0 comments on commit 8a1e291

Please sign in to comment.