diff --git a/CHANGELOG.md b/CHANGELOG.md index 0c221fca72f2246c3b78eadcf6ed3b440f1391bd..bcbad5a275e8cb5bef2a80182ffaa80008e2a5f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## v2.0.12 * Pomniejsze usprawnienia do TimerHeap +* Dodano `self` do @typed ## v2.0.11 diff --git a/satella/coding/typecheck.py b/satella/coding/typecheck.py index 6db2e52cc124b17b88065e8b2b492788e0afcfb5..ddbb9e1e17ea9ef01fa61eada6ba8797bc01a8d8 100644 --- a/satella/coding/typecheck.py +++ b/satella/coding/typecheck.py @@ -247,10 +247,14 @@ def typed(*t_args, **t_kwargs): You can also check for return type with kw argument of "returns", ie. - @typed(int, int, returns=int) - def sum(a, b): - return a+b - + @typed(int, int, returns=int) + def sum(a, b): + return a+b + + Or + @typed('self', a, b): + def method(self, a, b): + .. If you specify extra argument - mandatory=True - type will always be checked, regardless if debug mode is enabled @@ -266,6 +270,7 @@ def typed(*t_args, **t_kwargs): :param t_kwargs: """ + t_args = [q if t_args != 'self' else None for q in t_args] t_args = [(__typeinfo_to_tuple_of_types(x) if x is not None else None) for x in t_args] t_retarg = t_kwargs.get('returns', None) diff --git a/setup.py b/setup.py index 846f98fe05bb0cf9df0c478ca7515bb827b9f41d..395c0cae6bda2fe9ed29f6dc2856668cd45bf38a 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup, find_packages setup(name='satella', - version='2.0.12dev1', + version='2.0.12rc2', description=u'Utilities for writing servers in Python', author=u'Piotr MaĹlanka', author_email='piotrm@smok.co', diff --git a/tests/test_coding/test_debug.py b/tests/test_coding/test_debug.py index 26d678c9b1b2b8ee58f6427a28e97bb6a0f2d4dc..e5febb19bd93e782e2469f66d46c4b37833f7f1c 100644 --- a/tests/test_coding/test_debug.py +++ b/tests/test_coding/test_debug.py @@ -97,6 +97,28 @@ class TestTypecheck(unittest.TestCase): testa(a=None) testa(a=6) + def test_self(self): + + class Wtf(object): + @typed('self', int, int, returns=int) + def add(self, a, b): + return a+b + + Wtf().add(1,2) + + def test_T2(self): + + @typed((int, None)) + def testa(a=5): + pass + + self.assertRaises(TypeError, lambda: testa(2.0)) + testa(a=2.0) + self.assertRaises(TypeError, lambda: testa('yuyu')) + testa(a=None) + testa(a=6) + + def test_t3(self): def a(b, c):