diff --git a/setup.py b/setup.py index a413c5f678f..26056f280aa 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,7 @@ def read(rel_path): here = os.path.abspath(os.path.dirname(__file__)) # intentionally *not* adding an encoding option to open, See: # https://github.com/pypa/virtualenv/issues/201#issuecomment-3145690 - with open(os.path.join(here, rel_path), 'r') as fp: + with open(os.path.join(here, rel_path)) as fp: return fp.read() diff --git a/src/pip/_internal/req/constructors.py b/src/pip/_internal/req/constructors.py index 6f07e1bf057..810fc085988 100644 --- a/src/pip/_internal/req/constructors.py +++ b/src/pip/_internal/req/constructors.py @@ -140,7 +140,7 @@ def deduce_helpful_msg(req): msg = " The path does exist. " # Try to parse and check if it is a requirements file. try: - with open(req, 'r') as fp: + with open(req) as fp: # parse first line only next(parse_requirements(fp.read())) msg += ( diff --git a/src/pip/_internal/req/req_uninstall.py b/src/pip/_internal/req/req_uninstall.py index 519b79166a4..64890e33912 100644 --- a/src/pip/_internal/req/req_uninstall.py +++ b/src/pip/_internal/req/req_uninstall.py @@ -529,7 +529,7 @@ def from_dist(cls, dist): elif develop_egg_link: # develop egg - with open(develop_egg_link, 'r') as fh: + with open(develop_egg_link) as fh: link_pointer = os.path.normcase(fh.readline().strip()) assert (link_pointer == dist.location), ( 'Egg-link {} does not match installed location of {} ' diff --git a/tests/functional/test_install.py b/tests/functional/test_install.py index b60221b3438..e474ff04635 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -1304,7 +1304,7 @@ def test_install_log(script, data, tmpdir): 'install', data.src.joinpath('chattymodule')] result = script.pip(*args) assert 0 == result.stdout.count("HELLO FROM CHATTYMODULE") - with open(f, 'r') as fp: + with open(f) as fp: # one from egg_info, one from install assert 2 == fp.read().count("HELLO FROM CHATTYMODULE") @@ -1327,7 +1327,8 @@ def test_cleanup_after_failed_wheel(script, with_wheel): # One of the effects of not cleaning up is broken scripts: script_py = script.bin_path / "script.py" assert script_py.exists(), script_py - shebang = open(script_py, 'r').readline().strip() + with open(script_py) as f: + shebang = f.readline().strip() assert shebang != '#!python', shebang # OK, assert that we *said* we were cleaning up: # /!\ if in need to change this, also change test_pep517_no_legacy_cleanup diff --git a/tests/functional/test_no_color.py b/tests/functional/test_no_color.py index 48ed3ff7848..3fd943f9327 100644 --- a/tests/functional/test_no_color.py +++ b/tests/functional/test_no_color.py @@ -33,7 +33,7 @@ def get_run_output(option): pytest.skip("Unable to capture output using script: " + cmd) try: - with open("/tmp/pip-test-no-color.txt", "r") as output_file: + with open("/tmp/pip-test-no-color.txt") as output_file: retval = output_file.read() return retval finally: diff --git a/tests/functional/test_vcs_bazaar.py b/tests/functional/test_vcs_bazaar.py index ad24d73d5ba..57fee51e780 100644 --- a/tests/functional/test_vcs_bazaar.py +++ b/tests/functional/test_vcs_bazaar.py @@ -64,7 +64,7 @@ def test_export_rev(script, tmpdir): url = hide_url('bzr+' + _test_path_to_file_url(source_dir) + '@1') Bazaar().export(str(export_dir), url=url) - with open(export_dir / 'test_file', 'r') as f: + with open(export_dir / 'test_file') as f: assert f.read() == 'something initial' diff --git a/tools/automation/release/__init__.py b/tools/automation/release/__init__.py index 768bbcec6b1..a10ccd1f55c 100644 --- a/tools/automation/release/__init__.py +++ b/tools/automation/release/__init__.py @@ -91,7 +91,7 @@ def generate_news(session: Session, version: str) -> None: def update_version_file(version: str, filepath: str) -> None: - with open(filepath, "r", encoding="utf-8") as f: + with open(filepath, encoding="utf-8") as f: content = list(f) file_modified = False