diff --git a/pyproject.toml b/pyproject.toml index 630eef5e7..d54d7b6b9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -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 diff --git a/sphinx/cmd/build.py b/sphinx/cmd/build.py index 57430507d..811838c9d 100644 --- a/sphinx/cmd/build.py +++ b/sphinx/cmd/build.py @@ -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)) diff --git a/sphinx/ext/doctest.py b/sphinx/ext/doctest.py index db62f06b5..c55ef2fa7 100644 --- a/sphinx/ext/doctest.py +++ b/sphinx/ext/doctest.py @@ -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))) diff --git a/sphinx/ext/githubpages.py b/sphinx/ext/githubpages.py index a30986467..ddb8dc75a 100644 --- a/sphinx/ext/githubpages.py +++ b/sphinx/ext/githubpages.py @@ -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) diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index 6a612f2ab..c84506f39 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -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))