with
statements can be merged PTC-W0062With
statements` 76
77async def download_with_progress(url, path, message, unzip_bot):
78 try:
79 async with ClientSession() as session: 80 async with session.get(url, timeout=None, allow_redirects=True) as resp:
81 total_size = int(resp.headers.get("Content-Length", 0))
82 current_size = 0
With
statements` 63
64async def download(url, path):
65 try:
66 async with ClientSession() as session: 67 async with session.get(url, timeout=None, allow_redirects=True) as resp:
68 async with openfile(path, mode="wb") as file:
69 async for chunk in resp.content.iter_chunked(Config.CHUNK_SIZE):
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()