Вот мой код декоратора.По какой-то причине я получаю UnboundLocalError, но не могу его найти.
>>> def validate(schema=None):
def wrap(f):
def _f(*args, **kwargs):
if not schema:
schema = f.__name__
print schema
return f()
return _f
return wrap
>>> @validate()
def some_function():
print 'some function'
>>> some_function()
Traceback (most recent call last):
File "<pyshell#27>", line 1, in <module>
some_function()
File "<pyshell#22>", line 4, in _f
if not schema:
UnboundLocalError: local variable 'schema' referenced before assignment
>>>
Итак, я подумал, может быть, лучше разместить здесь.Я мог что-то упустить.
Спасибо.