with
statements can be merged PTC-W0062With
statements`323
324 @staticmethod
325 async def get_raw(link):
326 async with aiohttp.ClientSession() as session:327 async with session.get(link) as resp:
328 return await resp.read()
With
statements`317
318 @staticmethod
319 async def get_text(link):
320 async with aiohttp.ClientSession() as session:321 async with session.get(link) as resp:
322 return await resp.text()
323
With
statements`311class AioHttp:
312 @staticmethod
313 async def get_json(link):
314 async with aiohttp.ClientSession() as session:315 async with session.get(link) as resp:
316 return await resp.json()
317
With
statements`114
115
116async def postTextToDogBin(text):
117 async with aiohttp.ClientSession() as session:118 async with session.post('https://nekobin.com/api/documents', json={"content": text}) as response:
119 respJson = await response.json()
120 return f"https://nekobin.com/{respJson.get('result').get('key')}.py"
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()