Fix SIM115 (use context handler for opening files)

This commit is contained in:
Adam Turner 2023-08-13 23:17:59 +01:00
parent 08dbaa793e
commit f844055dda
5 changed files with 5 additions and 5 deletions

View File

@ -271,7 +271,6 @@ ignore = [
"SIM105", # use contextlib.suppress
"SIM108", # use ternary operator
"SIM114", # combine if branches using logical or operator
"SIM115", # use context handler for opening files
# flake8-self
"SLF001", # private member accessed
# flake8-print

View File

@ -241,7 +241,7 @@ def _parse_arguments(argv: list[str] = sys.argv[1:]) -> argparse.Namespace:
try:
warnfile = path.abspath(args.warnfile)
ensuredir(path.dirname(warnfile))
warnfp = open(args.warnfile, 'w', encoding="utf-8")
warnfp = open(args.warnfile, 'w', encoding="utf-8") # NoQA: SIM115
except Exception as exc:
parser.error(__('cannot open warning file %r: %s') % (
args.warnfile, exc))

View File

@ -304,7 +304,8 @@ class DocTestBuilder(Builder):
date = time.strftime('%Y-%m-%d %H:%M:%S')
self.outfile = open(path.join(self.outdir, 'output.txt'), 'w', encoding='utf-8')
outpath = self.outdir.joinpath('output.txt')
self.outfile = outpath.open('w', encoding='utf-8') # NoQA: SIM115
self.outfile.write(('Results of doctest builder run on %s\n'
'==================================%s\n') %
(date, '=' * len(date)))

View File

@ -36,7 +36,7 @@ def create_nojekyll_and_cname(app: Sphinx, env: BuildEnvironment) -> None:
if app.builder.format != 'html':
return
open(os.path.join(app.builder.outdir, '.nojekyll'), 'wb').close()
app.builder.outdir.joinpath('.nojekyll').touch()
cname_path = os.path.join(app.builder.outdir, 'CNAME')
domain = _get_domain_from_url(app.config.html_baseurl)

View File

@ -182,7 +182,7 @@ def fetch_inventory(app: Sphinx, uri: str, inv: str) -> Inventory:
if '://' in inv:
f = _read_from_url(inv, config=app.config)
else:
f = open(path.join(app.srcdir, inv), 'rb')
f = open(path.join(app.srcdir, inv), 'rb') # NoQA: SIM115
except Exception as err:
err.args = ('intersphinx inventory %r not fetchable due to %s: %s',
inv, err.__class__, str(err))