Skip to content

Commit

Permalink
Merge pull request #9591 from hexagonrecursion/open
Browse files Browse the repository at this point in the history
Replace `open(file, 'r')` with `open(file)`
  • Loading branch information
pradyunsg authored Feb 23, 2021
2 parents 270ddd3 + 20688ee commit baaf66f
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 8 deletions.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()


Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/req/constructors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 += (
Expand Down
2 changes: 1 addition & 1 deletion src/pip/_internal/req/req_uninstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {} '
Expand Down
5 changes: 3 additions & 2 deletions tests/functional/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_no_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/test_vcs_bazaar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'


Expand Down
2 changes: 1 addition & 1 deletion tools/automation/release/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit baaf66f

Please sign in to comment.