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

'self' for typed

parent b9a898d7
No related branches found
No related tags found
No related merge requests found
## v2.0.12
* Pomniejsze usprawnienia do TimerHeap
* Dodano `self` do @typed
## v2.0.11
......
......@@ -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)
......
......@@ -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',
......
......@@ -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):
......
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