gpt4 book ai didi

python - 皮林特 R1720 : Unnecessary "elif" after "raise" (no-else-raise)

转载 作者:太空宇宙 更新时间:2023-11-03 14:38:23 28 4
gpt4 key购买 nike

我有以下代码

    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)

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

最佳答案

    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 代替

关于python - 皮林特 R1720 : Unnecessary "elif" after "raise" (no-else-raise),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55632832/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com