local variable 'sub_type' referenced before assignment