From de136a11a787b9830fcebcd9003424f8a1a4da75 Mon Sep 17 00:00:00 2001 From: Piotr Maslanka <piotr.maslanka@henrietta.com.pl> Date: Tue, 5 Sep 2017 22:14:54 +0200 Subject: [PATCH] test for expected behaviour --- satella/coding/typecheck.py | 1 + tests/test_coding/test_debug.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/satella/coding/typecheck.py b/satella/coding/typecheck.py index f3d89e58..6db2e52c 100644 --- a/satella/coding/typecheck.py +++ b/satella/coding/typecheck.py @@ -265,6 +265,7 @@ def typed(*t_args, **t_kwargs): :param t_args: :param t_kwargs: """ + 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/tests/test_coding/test_debug.py b/tests/test_coding/test_debug.py index 486d0cad..26d678c9 100644 --- a/tests/test_coding/test_debug.py +++ b/tests/test_coding/test_debug.py @@ -6,6 +6,25 @@ from satella.coding import typed, CallSignature class TestTypecheck(unittest.TestCase): + def test_cls(self): + # if we don't care about apps + class Lol(object): + @typed(returns=int) + def zomg(self, a): + return a + + Lol().zomg(2) + self.assertRaises(TypeError, lambda: Lol().zomg('a')) + + def test_cls_test(self): + + class Lol(object): + # this should fail, since the first argument the decorator gets is "self", because decorators always get FUNCTION objects! + @typed(int, returns=int) + def zomg(self, a): + return a + + self.assertRaises(TypeError, lambda: Lol().zomg(2)) def test_ta(self): -- GitLab