Skip to content

Commit baaf66f

Browse files
authored
Merge pull request #9591 from hexagonrecursion/open
Replace `open(file, 'r')` with `open(file)`
2 parents 270ddd3 + 20688ee commit baaf66f

File tree

7 files changed

+9
-8
lines changed

7 files changed

+9
-8
lines changed

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def read(rel_path):
99
here = os.path.abspath(os.path.dirname(__file__))
1010
# intentionally *not* adding an encoding option to open, See:
1111
# https://github.com/pypa/virtualenv/issues/201#issuecomment-3145690
12-
with open(os.path.join(here, rel_path), 'r') as fp:
12+
with open(os.path.join(here, rel_path)) as fp:
1313
return fp.read()
1414

1515

src/pip/_internal/req/constructors.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def deduce_helpful_msg(req):
140140
msg = " The path does exist. "
141141
# Try to parse and check if it is a requirements file.
142142
try:
143-
with open(req, 'r') as fp:
143+
with open(req) as fp:
144144
# parse first line only
145145
next(parse_requirements(fp.read()))
146146
msg += (

src/pip/_internal/req/req_uninstall.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ def from_dist(cls, dist):
529529

530530
elif develop_egg_link:
531531
# develop egg
532-
with open(develop_egg_link, 'r') as fh:
532+
with open(develop_egg_link) as fh:
533533
link_pointer = os.path.normcase(fh.readline().strip())
534534
assert (link_pointer == dist.location), (
535535
'Egg-link {} does not match installed location of {} '

tests/functional/test_install.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1304,7 +1304,7 @@ def test_install_log(script, data, tmpdir):
13041304
'install', data.src.joinpath('chattymodule')]
13051305
result = script.pip(*args)
13061306
assert 0 == result.stdout.count("HELLO FROM CHATTYMODULE")
1307-
with open(f, 'r') as fp:
1307+
with open(f) as fp:
13081308
# one from egg_info, one from install
13091309
assert 2 == fp.read().count("HELLO FROM CHATTYMODULE")
13101310

@@ -1327,7 +1327,8 @@ def test_cleanup_after_failed_wheel(script, with_wheel):
13271327
# One of the effects of not cleaning up is broken scripts:
13281328
script_py = script.bin_path / "script.py"
13291329
assert script_py.exists(), script_py
1330-
shebang = open(script_py, 'r').readline().strip()
1330+
with open(script_py) as f:
1331+
shebang = f.readline().strip()
13311332
assert shebang != '#!python', shebang
13321333
# OK, assert that we *said* we were cleaning up:
13331334
# /!\ if in need to change this, also change test_pep517_no_legacy_cleanup

tests/functional/test_no_color.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def get_run_output(option):
3333
pytest.skip("Unable to capture output using script: " + cmd)
3434

3535
try:
36-
with open("/tmp/pip-test-no-color.txt", "r") as output_file:
36+
with open("/tmp/pip-test-no-color.txt") as output_file:
3737
retval = output_file.read()
3838
return retval
3939
finally:

tests/functional/test_vcs_bazaar.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def test_export_rev(script, tmpdir):
6464
url = hide_url('bzr+' + _test_path_to_file_url(source_dir) + '@1')
6565
Bazaar().export(str(export_dir), url=url)
6666

67-
with open(export_dir / 'test_file', 'r') as f:
67+
with open(export_dir / 'test_file') as f:
6868
assert f.read() == 'something initial'
6969

7070

tools/automation/release/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def generate_news(session: Session, version: str) -> None:
9191

9292

9393
def update_version_file(version: str, filepath: str) -> None:
94-
with open(filepath, "r", encoding="utf-8") as f:
94+
with open(filepath, encoding="utf-8") as f:
9595
content = list(f)
9696

9797
file_modified = False

0 commit comments

Comments
 (0)