pylint R1720:在“提高”之后不必要的“ elif”(无其他提高)

时间:2019-04-11 12:44:34

标签: python pylint

我有以下代码

    if self.download_format == 'mp3':
        raise NotImplementedError
    elif self.download_format == 'wav':
        with NamedTemporaryFile(suffix='.wav') as wavfile:
            self.download_wav_recording(call, wavfile.name)
            convert_wav_to_mp3(wavfile.name, filename)

然后pylint报告此错误

R1720: Unnecessary "elif" after "raise" (no-else-raise)

此错误的动机是什么?为什么此代码不正确?

1 个答案:

答案 0 :(得分:3)

    if self.download_format == 'mp3':
        raise NotImplementedError
    elif self.download_format == 'wav':
        with NamedTemporaryFile(suffix='.wav') as wavfile:
            self.download_wav_recording(call, wavfile.name)
            convert_wav_to_mp3(wavfile.name, filename)

这等效于

    if self.download_format == 'mp3':
        raise NotImplementedError
    if self.download_format == 'wav':
      with NamedTemporaryFile(suffix='.wav') as wavfile:
          self.download_wav_recording(call, wavfile.name)
          convert_wav_to_mp3(wavfile.name, filename)

从pylint发出警告

raise导致控制流中断-因此您无需使用elif,而可以使用if