Skip to content

Commit f844055

Browse files
committed
Fix SIM115 (use context handler for opening files)
1 parent 08dbaa7 commit f844055

File tree

5 files changed

+5
-5
lines changed

5 files changed

+5
-5
lines changed

pyproject.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ ignore = [
271271
"SIM105", # use contextlib.suppress
272272
"SIM108", # use ternary operator
273273
"SIM114", # combine if branches using logical or operator
274-
"SIM115", # use context handler for opening files
275274
# flake8-self
276275
"SLF001", # private member accessed
277276
# flake8-print

sphinx/cmd/build.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ def _parse_arguments(argv: list[str] = sys.argv[1:]) -> argparse.Namespace:
241241
try:
242242
warnfile = path.abspath(args.warnfile)
243243
ensuredir(path.dirname(warnfile))
244-
warnfp = open(args.warnfile, 'w', encoding="utf-8")
244+
warnfp = open(args.warnfile, 'w', encoding="utf-8") # NoQA: SIM115
245245
except Exception as exc:
246246
parser.error(__('cannot open warning file %r: %s') % (
247247
args.warnfile, exc))

sphinx/ext/doctest.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ def init(self) -> None:
304304

305305
date = time.strftime('%Y-%m-%d %H:%M:%S')
306306

307-
self.outfile = open(path.join(self.outdir, 'output.txt'), 'w', encoding='utf-8')
307+
outpath = self.outdir.joinpath('output.txt')
308+
self.outfile = outpath.open('w', encoding='utf-8') # NoQA: SIM115
308309
self.outfile.write(('Results of doctest builder run on %s\n'
309310
'==================================%s\n') %
310311
(date, '=' * len(date)))

sphinx/ext/githubpages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def create_nojekyll_and_cname(app: Sphinx, env: BuildEnvironment) -> None:
3636
if app.builder.format != 'html':
3737
return
3838

39-
open(os.path.join(app.builder.outdir, '.nojekyll'), 'wb').close()
39+
app.builder.outdir.joinpath('.nojekyll').touch()
4040
cname_path = os.path.join(app.builder.outdir, 'CNAME')
4141

4242
domain = _get_domain_from_url(app.config.html_baseurl)

sphinx/ext/intersphinx.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ def fetch_inventory(app: Sphinx, uri: str, inv: str) -> Inventory:
182182
if '://' in inv:
183183
f = _read_from_url(inv, config=app.config)
184184
else:
185-
f = open(path.join(app.srcdir, inv), 'rb')
185+
f = open(path.join(app.srcdir, inv), 'rb') # NoQA: SIM115
186186
except Exception as err:
187187
err.args = ('intersphinx inventory %r not fetchable due to %s: %s',
188188
inv, err.__class__, str(err))

0 commit comments

Comments
 (0)