Apply refurb/ruff rule FURB145 (#11848)

This commit is contained in:
Dimitri Papadopoulos Orfanos 2024-01-04 04:49:53 +01:00 committed by GitHub
parent 0cf8398caf
commit bd03bbbf0e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 10 additions and 10 deletions

View File

@ -126,7 +126,7 @@ class ChangeSetDomain(Domain):
def clear_doc(self, docname: str) -> None: def clear_doc(self, docname: str) -> None:
for changes in self.changesets.values(): for changes in self.changesets.values():
for changeset in changes[:]: for changeset in changes.copy():
if changeset.docname == docname: if changeset.docname == docname:
changes.remove(changeset) changes.remove(changeset)

View File

@ -77,7 +77,7 @@ class EventManager:
def disconnect(self, listener_id: int) -> None: def disconnect(self, listener_id: int) -> None:
"""Disconnect a handler.""" """Disconnect a handler."""
for listeners in self.listeners.values(): for listeners in self.listeners.values():
for listener in listeners[:]: for listener in listeners.copy():
if listener.id == listener_id: if listener.id == listener_id:
listeners.remove(listener) listeners.remove(listener)

View File

@ -168,7 +168,7 @@ def create_modules_toc_file(modules: list[str], opts: Any, name: str = 'modules'
"""Create the module's index.""" """Create the module's index."""
modules.sort() modules.sort()
prev_module = '' prev_module = ''
for module in modules[:]: for module in modules.copy():
# look if the module is a subpackage and, if yes, ignore it # look if the module is a subpackage and, if yes, ignore it
if module.startswith(prev_module + '.'): if module.startswith(prev_module + '.'):
modules.remove(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_pkg = is_packagedir(None, files)
is_namespace = not is_pkg and implicit_namespaces is_namespace = not is_pkg and implicit_namespaces
if is_pkg: if is_pkg:
for f in files[:]: for f in files.copy():
if is_initpy(f): if is_initpy(f):
files.remove(f) files.remove(f)
files.insert(0, f) files.insert(0, f)

View File

@ -221,7 +221,7 @@ def between(
return return
deleted = 0 deleted = 0
delete = not exclude delete = not exclude
orig_lines = lines[:] orig_lines = lines.copy()
for i, line in enumerate(orig_lines): for i, line in enumerate(orig_lines):
if delete: if delete:
lines.pop(i - deleted) lines.pop(i - deleted)

View File

@ -389,7 +389,7 @@ def _process_docstring(app: Sphinx, what: str, name: str, obj: Any,
docstring = GoogleDocstring(result_lines, app.config, app, what, name, docstring = GoogleDocstring(result_lines, app.config, app, what, name,
obj, options) obj, options)
result_lines = docstring.lines() result_lines = docstring.lines()
lines[:] = result_lines[:] lines[:] = result_lines.copy()
def _skip_member(app: Sphinx, what: str, name: str, obj: Any, def _skip_member(app: Sphinx, what: str, name: str, obj: Any,

View File

@ -174,7 +174,7 @@ def make_app(test_params: dict, monkeypatch: Any) -> Generator[Callable, None, N
instead of using SphinxTestApp class directory. instead of using SphinxTestApp class directory.
""" """
apps = [] apps = []
syspath = sys.path[:] syspath = sys.path.copy()
def make(*args, **kwargs): def make(*args, **kwargs):
status, warning = StringIO(), StringIO() status, warning = StringIO(), StringIO()

View File

@ -109,7 +109,7 @@ class SphinxTestApp(application.Sphinx):
confoverrides = {} confoverrides = {}
warningiserror = False 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_directives = directives._directives.copy() # type: ignore[attr-defined]
self._saved_roles = roles._roles.copy() # type: ignore[attr-defined] self._saved_roles = roles._roles.copy() # type: ignore[attr-defined]

View File

@ -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): for root, dirs, files in os.walk(source, followlinks=True):
reldir = relative_path(source, root) # type: ignore[arg-type] reldir = relative_path(source, root) # type: ignore[arg-type]
for dir in dirs[:]: for dir in dirs.copy():
if excluded(posixpath.join(reldir, dir)): if excluded(posixpath.join(reldir, dir)):
dirs.remove(dir) dirs.remove(dir)
else: else:

View File

@ -321,7 +321,7 @@ class LaTeXTranslator(SphinxTranslator):
self.elements = self.builder.context.copy() self.elements = self.builder.context.copy()
# initial section names # initial section names
self.sectionnames = LATEXSECTIONNAMES[:] self.sectionnames = LATEXSECTIONNAMES.copy()
if self.theme.toplevel_sectioning == 'section': if self.theme.toplevel_sectioning == 'section':
self.sectionnames.remove('chapter') self.sectionnames.remove('chapter')