adding some decorator stuff

This commit is contained in:
Alex Yatskov 2012-04-22 17:22:37 -07:00
parent 6c8e2dfbb8
commit 9f4c4dcf7f
2 changed files with 35 additions and 0 deletions

23
metacall.py Normal file → Executable file
View File

@ -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

12
testing.py Executable file
View File

@ -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)