with
statements can be merged PTC-W0062With
statements`109
110def test_unzip_osx_bundle_strip(capsys): # pylint: disable=unused-argument
111 """Test that ZIP files with single top level directory are stripped."""
112 with captured_exit_code() as get_exit_code:113 with tempfile.TemporaryDirectory() as tmp_dir_name:
114 # Set the temp directory as the current working directory
115 os.chdir(tmp_dir_name)
With
statements`127
128def test_unzip_osx_bundle(capsys): # pylint: disable=unused-argument
129 """Test that OSX bundles are unzipped and .app is not stripped."""
130 with captured_exit_code() as get_exit_code:131 with tempfile.TemporaryDirectory() as tmp_dir_name:
132 # Set the temp directory as the current working directory
133 os.chdir(tmp_dir_name)
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()