Skip to content
Snippets Groups Projects
Commit 6da40943 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

.

parent 70960fc9
No related branches found
No related tags found
No related merge requests found
...@@ -3,3 +3,6 @@ ...@@ -3,3 +3,6 @@
Satella typechecking is a complex solution for: Satella typechecking is a complex solution for:
* extracting callable arguments signature * extracting callable arguments signature
* checking type compatibility at runtime * checking type compatibility at runtime
If you do `@typed` on a class method, skip the type of self or cls, since Satella will
detect that it's annotating a class method.
\ No newline at end of file
...@@ -282,10 +282,12 @@ def typed(*t_args, **t_kwargs): ...@@ -282,10 +282,12 @@ def typed(*t_args, **t_kwargs):
@functools.wraps(fun) @functools.wraps(fun)
def inner(*args, **kwargs): def inner(*args, **kwargs):
if inspect.ismethod(fun): if isinstance(fun, types.MethodType) or inspect.ismethod(fun) or hasattr(fun, 'im_class'): # instancemethod or classmethod
t_args = itertools.chain([None], t_args) cargs = args[1:]
else:
cargs = args
for argument, typedescr in zip(args, t_args): for argument, typedescr in zip(cargs, t_args):
if typedescr is not None: if typedescr is not None:
if not isinstance(argument, typedescr): if not isinstance(argument, typedescr):
raise TypeError('Got %s, expected %s' % (type(argument), typedescr)) raise TypeError('Got %s, expected %s' % (type(argument), typedescr))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment