with
statements can be merged PTC-W0062With
statements`454 raise commands.BadArgument("That command is on cooldown.")
455
456 await ctx.defer(ephemeral=False)
457 async with aiohttp.ClientSession(headers={"Authorization": f"Bearer {cfg.open_ai_token}", "Content-Type": "application/json"}) as client:458 async with client.post(f"https://api.openai.com/v1/engines/text-davinci-001/completions", json={
459 "prompt": prompt,
460 "temperature": 0.7,
With
statements`279
280 @cached(ttl=3600)
281 async def fetch_cij_or_news_database(self):
282 async with aiohttp.ClientSession() as session:283 async with session.get("https://raw.githubusercontent.com/DiscordGIR/CIJOrNewsFilter/main/database.json") as resp:
284 if resp.status == 200:
285 data = await resp.text()
With
statements`51
52 @cached(ttl=3600)
53 async def get_tiktok_redirect(self, link: str):
54 async with aiohttp.ClientSession() as session:55 async with session.get(link, allow_redirects=False) as response:
56 if response.status != 301:
57 return
With
statements`157
158 @staticmethod
159 async def do_content_parsing(url):
160 async with aiohttp.ClientSession() as session:161 async with session.head(url) as resp:
162 if resp.status != 200:
163 return None
With
statements` 5
6async def emoji_thing():
7 emojis = None
8 async with aiohttp.ClientSession() as client: 9 async with client.get('https://unicode.org/emoji/charts/full-emoji-list.html') as resp:
10 assert resp.status == 200
11 soup = BeautifulSoup(await resp.text(), 'html.parser')
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.
with open("file1", "w") as file1:
with open("file2", "w") as file2:
doSomething()
with open("file1", "w") as file1, open("file2", "w") as file2:
doSomething()