python local variable referenced before assignment nested function