Skip to content

Instantly share code, notes, and snippets.

@cocoatomo
Created August 11, 2010 16:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cocoatomo/519302 to your computer and use it in GitHub Desktop.
Save cocoatomo/519302 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python
# -*- encoding:utf-8 -*-
def range(**ranged):
def arged(f):
def ret(*argv, **d):
minv = ranged['min']
maxv = ranged['max']
print('*** range check. min: {0}, max: {1} ***'.format(minv, maxv))
for a in argv:
if a < minv:
print('-> lower')
elif a > maxv:
print('-> exceed')
else:
print('-> valid')
f(*argv, **d)
return ret
return arged
def notnone(f):
def ret(*argv, **d):
for a in argv:
if a is None:
raise ValueError('is None')
print('None check passed')
f(*argv, **d)
return ret
@range(min=5, max=8)
def hoge(i):
print('hoge called with {0}'.format(i))
@notnone
def fuga(a):
print(a)
if __name__ == '__main__':
hoge(5)
hoge(3)
hoge(9)
fuga(123)
fuga('hoge')
fuga(None)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment