Consider merging collapsible
With
statements`205 ) # 如果没有提供下载地址则用默认的
206 print("Download URL:", _url)
207 # 从网络上下载
208 async with ClientSession(headers={"user-agent": "SSRSpeedN"}) as session:209 async with session.get(_url, proxy=proxy, timeout=20) as resp:
210 if resp.status != 200:
211 raise Exception(f"NetworkError: {resp.status}==>\t{_url}")
Consider merging collapsible
With
statements`118
119 def get_emoji(self, emoji: str, /) -> Optional[BytesIO]:
120 file_path = self.get_file_path(emoji)
121 with contextlib.suppress(FileNotFoundError):122 with open(file_path, "rb") as file:
123 return BytesIO(file.read())
124 return None
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()