From bd03bbbf0eb30d2340d28cf8241db5a2a035f799 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos Orfanos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 4 Jan 2024 04:49:53 +0100 Subject: [PATCH] Apply refurb/ruff rule FURB145 (#11848) --- sphinx/domains/changeset.py | 2 +- sphinx/events.py | 2 +- sphinx/ext/apidoc.py | 4 ++-- sphinx/ext/autodoc/__init__.py | 2 +- sphinx/ext/napoleon/__init__.py | 2 +- sphinx/testing/fixtures.py | 2 +- sphinx/testing/util.py | 2 +- sphinx/util/fileutil.py | 2 +- sphinx/writers/latex.py | 2 +- 9 files changed, 10 insertions(+), 10 deletions(-) diff --git a/sphinx/domains/changeset.py b/sphinx/domains/changeset.py index 7cfe3829e..849779516 100644 --- a/sphinx/domains/changeset.py +++ b/sphinx/domains/changeset.py @@ -126,7 +126,7 @@ class ChangeSetDomain(Domain): def clear_doc(self, docname: str) -> None: for changes in self.changesets.values(): - for changeset in changes[:]: + for changeset in changes.copy(): if changeset.docname == docname: changes.remove(changeset) diff --git a/sphinx/events.py b/sphinx/events.py index dad33aa63..f406a399d 100644 --- a/sphinx/events.py +++ b/sphinx/events.py @@ -77,7 +77,7 @@ class EventManager: def disconnect(self, listener_id: int) -> None: """Disconnect a handler.""" for listeners in self.listeners.values(): - for listener in listeners[:]: + for listener in listeners.copy(): if listener.id == listener_id: listeners.remove(listener) diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py index 90213fa8b..d99438dff 100644 --- a/sphinx/ext/apidoc.py +++ b/sphinx/ext/apidoc.py @@ -168,7 +168,7 @@ def create_modules_toc_file(modules: list[str], opts: Any, name: str = 'modules' """Create the module's index.""" modules.sort() prev_module = '' - for module in modules[:]: + for module in modules.copy(): # look if the module is a subpackage and, if yes, ignore it if module.startswith(prev_module + '.'): modules.remove(module) @@ -268,7 +268,7 @@ def recurse_tree(rootpath: str, excludes: Sequence[re.Pattern[str]], opts: Any, is_pkg = is_packagedir(None, files) is_namespace = not is_pkg and implicit_namespaces if is_pkg: - for f in files[:]: + for f in files.copy(): if is_initpy(f): files.remove(f) files.insert(0, f) diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 14292d10f..400807898 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -221,7 +221,7 @@ def between( return deleted = 0 delete = not exclude - orig_lines = lines[:] + orig_lines = lines.copy() for i, line in enumerate(orig_lines): if delete: lines.pop(i - deleted) diff --git a/sphinx/ext/napoleon/__init__.py b/sphinx/ext/napoleon/__init__.py index fd98ffbcd..777838cb6 100644 --- a/sphinx/ext/napoleon/__init__.py +++ b/sphinx/ext/napoleon/__init__.py @@ -389,7 +389,7 @@ def _process_docstring(app: Sphinx, what: str, name: str, obj: Any, docstring = GoogleDocstring(result_lines, app.config, app, what, name, obj, options) result_lines = docstring.lines() - lines[:] = result_lines[:] + lines[:] = result_lines.copy() def _skip_member(app: Sphinx, what: str, name: str, obj: Any, diff --git a/sphinx/testing/fixtures.py b/sphinx/testing/fixtures.py index 154323bf9..8644c5193 100644 --- a/sphinx/testing/fixtures.py +++ b/sphinx/testing/fixtures.py @@ -174,7 +174,7 @@ def make_app(test_params: dict, monkeypatch: Any) -> Generator[Callable, None, N instead of using SphinxTestApp class directory. """ apps = [] - syspath = sys.path[:] + syspath = sys.path.copy() def make(*args, **kwargs): status, warning = StringIO(), StringIO() diff --git a/sphinx/testing/util.py b/sphinx/testing/util.py index e76d4010c..a704afbea 100644 --- a/sphinx/testing/util.py +++ b/sphinx/testing/util.py @@ -109,7 +109,7 @@ class SphinxTestApp(application.Sphinx): confoverrides = {} warningiserror = False - self._saved_path = sys.path[:] + self._saved_path = sys.path.copy() self._saved_directives = directives._directives.copy() # type: ignore[attr-defined] self._saved_roles = roles._roles.copy() # type: ignore[attr-defined] diff --git a/sphinx/util/fileutil.py b/sphinx/util/fileutil.py index 316ec3916..ddefb8ab2 100644 --- a/sphinx/util/fileutil.py +++ b/sphinx/util/fileutil.py @@ -81,7 +81,7 @@ def copy_asset(source: str | os.PathLike[str], destination: str | os.PathLike[st for root, dirs, files in os.walk(source, followlinks=True): reldir = relative_path(source, root) # type: ignore[arg-type] - for dir in dirs[:]: + for dir in dirs.copy(): if excluded(posixpath.join(reldir, dir)): dirs.remove(dir) else: diff --git a/sphinx/writers/latex.py b/sphinx/writers/latex.py index 43a090592..a0f64717e 100644 --- a/sphinx/writers/latex.py +++ b/sphinx/writers/latex.py @@ -321,7 +321,7 @@ class LaTeXTranslator(SphinxTranslator): self.elements = self.builder.context.copy() # initial section names - self.sectionnames = LATEXSECTIONNAMES[:] + self.sectionnames = LATEXSECTIONNAMES.copy() if self.theme.toplevel_sectioning == 'section': self.sectionnames.remove('chapter')