pylint R1720:“raise”后不必要的“elif”(no-else-raise)

Rya*_*der 9 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)
Run Code Online (Sandbox Code Playgroud)

并且pylint报这个错误

R1720: Unnecessary "elif" after "raise" (no-else-raise)
Run Code Online (Sandbox Code Playgroud)

这个错误的动机是什么?为什么这段代码不行?

rda*_*das 14

    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)
Run Code Online (Sandbox Code Playgroud)

这相当于

    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)
Run Code Online (Sandbox Code Playgroud)

因此来自pylint的警告

将raise导致控制流向被打乱-所以你不需要使用elif,并且可以使用if替代