From 9f4c4dcf7fee4f388ace4f414a049525fc1e9a00 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Sun, 22 Apr 2012 17:22:37 -0700 Subject: [PATCH] adding some decorator stuff --- metacall.py | 23 +++++++++++++++++++++++ testing.py | 12 ++++++++++++ 2 files changed, 35 insertions(+) mode change 100644 => 100755 metacall.py create mode 100755 testing.py diff --git a/metacall.py b/metacall.py old mode 100644 new mode 100755 index db2a406..ea308e1 --- a/metacall.py +++ b/metacall.py @@ -156,3 +156,26 @@ class Token: hash = (hash << 5) + hash + ord(c) return hash + + +# +# Descriptor +# + +class Descriptor: + def __init__(self, name, *types): + self.name = name + self.types = types + + +# +# callable +# + +def callable(*types): + def wrapper(func): + assert func.func_code.co_argcount == len(types) + func.descriptor = Descriptor(func.func_code.co_name, types) + return func + + return wrapper diff --git a/testing.py b/testing.py new file mode 100755 index 0000000..fab389b --- /dev/null +++ b/testing.py @@ -0,0 +1,12 @@ +#!/usr/bin/env python2 + +import metacall + +@metacall.callable(int, int, int) +def test(a, b, c): + print 'Hello world' + + + +test(1,2,3) +test(1,2,3)