Consider merging collapsible
With
statements`196 _url = self.download_url if download_url is None else download_url # 如果没有提供下载地址则用默认的
197 print("Download URL:", _url)
198 # 从网络上下载
199 async with ClientSession(headers={'user-agent': 'SSRSpeedN'}) as session:200 async with session.get(_url, proxy=proxy, timeout=20) as resp:
201 if resp.status == 200:
202 with open(savepath, 'wb') as f:
Description
Nested with
statements can be merged into a single compound with
statement.
This issue is raised only when there are no other statements between the nested with
statements.
Merging collapsible with
statements can decrease cognitive complexity, improving code readability.
Bad practice
with open("file1", "w") as file1:
with open("file2", "w") as file2:
doSomething()
Preferred
with open("file1", "w") as file1, open("file2", "w") as file2:
doSomething()