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

fixes #16

parent f7ddc233
No related branches found
No related tags found
No related merge requests found
## v2.0.22
## v2.0.22rc1
* ...
* fixes #16
## v2.0.21
......
......@@ -293,19 +293,21 @@ def istype(var, type_):
return any(istype(var, subtype) for subtype in type_)
try:
if type_ in (Callable, Iterable, Sequence, Mapping):
raise TypeError()
if isinstance(var, type_):
return True
except TypeError as e: # must be a typing.* annotation
try:
return all(hasattr(var, n) for n in {
Iterable: ('__iter__',),
Sequence: ('__iter__', '__getattr__', '__len__'),
Callable: ('__call__', ),
Mapping: ('__getitem__', ),
}[type(var)])
except KeyError:
pass
if type_ == Callable:
return hasattr(var, '__call__')
elif type_ == Iterable:
return hasattr(var, '__iter__')
elif type_ == Sequence:
return hasattr(var, '__iter__') and hasattr(var, '__getattr__') and hasattr(var, '__len__')
elif type_ == Mapping:
return hasattr(var, '__getitem__')
return type(var) == type_
......
[metadata]
name = satella
version = 2.0.22a1
version = 2.0.22rc1
description-file = README.md
author = Piotr Maślanka
author_email = piotrm@smok.co
......
......@@ -48,6 +48,13 @@ class TestTypecheck(unittest.TestCase):
p(None)
self.assertRaises(TypeError, lambda: p(5.0))
def test_lambda(self):
@typed(Callable)
def q(p):
pass
q(lambda: None)
def test_forarg(self):
@for_argument(int)
def testa(a):
......
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