Skip to content

Commit

Permalink
ruff: enable SIM115: Use context handler for opening files
Browse files Browse the repository at this point in the history
  • Loading branch information
giampaolo committed Dec 23, 2024
1 parent b42eccd commit 107daa1
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/issues.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,9 +159,10 @@ def get_repo():

@functools.lru_cache()
def _get_event_data():
ret = json.load(open(os.environ["GITHUB_EVENT_PATH"]))
pp(ret)
return ret
with open(open(os.environ["GITHUB_EVENT_PATH"])) as f:
ret = json.load(f)
pp(ret)
return ret


def is_event_new_issue():
Expand Down
2 changes: 1 addition & 1 deletion psutil/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -753,7 +753,7 @@ def open_text(fname):
# See:
# https://github.com/giampaolo/psutil/issues/675
# https://github.com/giampaolo/psutil/pull/733
fobj = open(
fobj = open( # noqa: SIM115
fname,
buffering=FILE_READ_BUFFER_SIZE,
encoding=ENCODING,
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ def attempt(exe):


PYTHON_EXE, PYTHON_EXE_ENV = _get_py_exe()
DEVNULL = open(os.devnull, 'r+')
DEVNULL = open(os.devnull, 'r+') # noqa: SIM115
atexit.register(DEVNULL.close)

VALID_PROC_STATUSES = [
Expand Down
2 changes: 1 addition & 1 deletion psutil/tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -1119,7 +1119,7 @@ def test_num_fds(self):
p = psutil.Process()
testfn = self.get_testfn()
start = p.num_fds()
file = open(testfn, 'w')
file = open(testfn, 'w') # noqa: SIM115
self.addCleanup(file.close)
assert p.num_fds() == start + 1
sock = socket.socket()
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ ignore = [
"S", # flake8-bandit
"SIM102", # Use a single `if` statement instead of nested `if` statements
"SIM105", # Use `contextlib.suppress(OSError)` instead of `try`-`except`-`pass`
"SIM115", # Use context handler for opening files
"SIM117", # Use a single `with` statement with multiple contexts instead of nested `with` statements
"SLF", # flake8-self
"TD", # all TODOs, XXXs, etc.
Expand Down

0 comments on commit 107daa1

Please sign in to comment.