我有以下代码
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)
此错误的动机是什么?为什么此代码不正确?
答案 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