python closure local variable referenced before assignment