with
statements can be merged PTC-W0062With
statements`339 getattr(self, "_fix_" + fix_type)(status)
340
341 def _fix_content_hash(self, status):
342 with self._write_local_file() as local_path:343 with io.job(_("{} {} uploading to node").format(
344 bold(self.node.name),
345 bold(self.id),
With
statements`246
247
248def get_file_contents(path):
249 with error_context(path=path):250 with open(path, 'rb') as f:
251 content = f.read()
252 return content
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()