From f13e10c9156466af7dc80b298705cb322e75e607 Mon Sep 17 00:00:00 2001 From: Andrey Bienkowski Date: Wed, 10 Feb 2021 13:20:11 +0300 Subject: [PATCH] Replace `open(file, 'r')` with `open(file)` --- setup.py | 2 +- src/pip/_internal/req/constructors.py | 2 +- src/pip/_internal/req/req_uninstall.py | 2 +- tests/functional/test_install.py | 4 ++-- tests/functional/test_no_color.py | 2 +- tests/functional/test_vcs_bazaar.py | 2 +- tools/automation/release/__init__.py | 2 +- 7 files changed, 8 insertions(+), 8 deletions(-) diff --git a/setup.py b/setup.py index 66820387b..f2ee075ad 100644 --- a/setup.py +++ b/setup.py @@ -11,7 +11,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 cfb1951b6..f722efe9a 100644 --- a/src/pip/_internal/req/constructors.py +++ b/src/pip/_internal/req/constructors.py @@ -145,7 +145,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 a37a378dd..0f2de9b0d 100644 --- a/src/pip/_internal/req/req_uninstall.py +++ b/src/pip/_internal/req/req_uninstall.py @@ -543,7 +543,7 @@ class UninstallPathSet: 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 1c0650c6f..7b331164b 100644 --- a/tests/functional/test_install.py +++ b/tests/functional/test_install.py @@ -1298,7 +1298,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") @@ -1321,7 +1321,7 @@ 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() + shebang = open(script_py).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 48ed3ff78..3fd943f93 100644 --- a/tests/functional/test_no_color.py +++ b/tests/functional/test_no_color.py @@ -33,7 +33,7 @@ def test_no_color(script): 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 ad24d73d5..57fee51e7 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 20775d5e2..645e7a116 100644 --- a/tools/automation/release/__init__.py +++ b/tools/automation/release/__init__.py @@ -90,7 +90,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