diff options
author | Pradyun Gedam <3275593+pradyunsg@users.noreply.github.com> | 2021-02-23 13:37:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-23 13:37:25 +0000 |
commit | baaf66f70d84cf3367d5b43fec16762ca9703810 (patch) | |
tree | 3dd125fddb8beb3022450e57a910de6b5a03da80 | |
parent | 270ddd3d034db844baaa30927331513b80fc4912 (diff) | |
parent | 20688ee8e8df1229312b0ed1a0b556ed7045c6b0 (diff) | |
download | pip-baaf66f70d84cf3367d5b43fec16762ca9703810.tar.gz |
Merge pull request #9591 from hexagonrecursion/open
Replace `open(file, 'r')` with `open(file)`
-rw-r--r-- | setup.py | 2 | ||||
-rw-r--r-- | src/pip/_internal/req/constructors.py | 2 | ||||
-rw-r--r-- | src/pip/_internal/req/req_uninstall.py | 2 | ||||
-rw-r--r-- | tests/functional/test_install.py | 5 | ||||
-rw-r--r-- | tests/functional/test_no_color.py | 2 | ||||
-rw-r--r-- | tests/functional/test_vcs_bazaar.py | 2 | ||||
-rw-r--r-- | tools/automation/release/__init__.py | 2 |
7 files changed, 9 insertions, 8 deletions
@@ -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 6f07e1bf0..810fc0859 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 519b79166..64890e339 100644 --- a/src/pip/_internal/req/req_uninstall.py +++ b/src/pip/_internal/req/req_uninstall.py @@ -529,7 +529,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 b60221b34..e474ff046 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 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 768bbcec6..a10ccd1f5 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 |