Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pylint

I have the following code

    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)

And pylint reports this error

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

What is the motivation for this error? why this code is not ok?

like image 601
Ryabchenko Alexander Avatar asked Apr 11 '19 12:04

Ryabchenko Alexander


1 Answers

    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)

This is equivalent to

    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)

Hence the warning from pylint

The raise causes control flow to be disrupted - so you don't need to use elif and can use if instead

like image 180
rdas Avatar answered Oct 23 '22 00:10

rdas