Skip to content

Commit

Permalink
done
Browse files Browse the repository at this point in the history
  • Loading branch information
ken-morel committed Jun 2, 2024
1 parent a1d8ac6 commit 14ee7cd
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/pyoload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,10 @@ class Checks(PyoloadAnnotation):
Pyoload annotation holding several checks
"""

def __init__(self: PyoloadAnnotation, **checks):
def __init__(
self: PyoloadAnnotation,
**checks: dict[str, Callable[Any, Any]]
):
"""def __init__(self: PyoloadAnnotation, **checks)
crates the check object,e.g
Expand Down Expand Up @@ -364,7 +367,7 @@ def __set__(self: Any, obj: Any, value: Any):
self.value = self(value)


def typeMatch(val: Any, spec: type) -> bool:
def typeMatch(val: Any, spec: Any) -> bool:
"""
recursively checks if type matches
:param val: The value to typecheck
Expand Down Expand Up @@ -535,7 +538,7 @@ def wrapper(*args, **kw):
__overloads__: dict[str, list[Callable]] = {}


def overload(func: callable, name: str | None = None):
def overload(func: Callable, name: str | None = None):
"""
returns a wrapper over the passed function
which typechecks arguments on each call
Expand All @@ -554,7 +557,7 @@ def overload(func: callable, name: str | None = None):
__overloads__[name] = []
__overloads__[name].append(annotate(func, True))

@wraps(func)
@wraps(func: Callable)
def wrapper(*args, **kw):
for f in __overloads__[name]:
try:
Expand All @@ -577,7 +580,7 @@ def wrapper(*args, **kw):
return wrapper


def annotateClass(cls):
def annotateClass(cls: Any):
"""
Annotates a class object, wrapping and replacing over it's __setattr__
and typechecking over each attribute assignment.
Expand Down Expand Up @@ -611,8 +614,7 @@ def new_setter(self: Any, name: str, value: Any) -> Any:
resolveAnnotations(self)

if name not in self.__annotations__:
if value is not None:
self.__annotations__[name] = type(value)
return setter(self, name, value) # do not check if no annotations
elif isinstance(self.__annotations__[name], Cast):
return setter(self, name, self.__annotations__[name](value))
elif not typeMatch(value, self.__annotations__[name]):
Expand All @@ -626,5 +628,5 @@ def new_setter(self: Any, name: str, value: Any) -> Any:
return cls


__version__ = '1.1.2'
__version__ = '1.1.3'
__author__ = 'ken-morel'

0 comments on commit 14ee7cd

Please sign in to comment.