summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.flake81
-rw-r--r--pyproject.toml1
-rw-r--r--sphinx/builders/linkcheck.py10
-rw-r--r--sphinx/ext/apidoc.py25
-rw-r--r--sphinx/ext/coverage.py8
-rw-r--r--sphinx/ext/napoleon/docstring.py2
-rw-r--r--sphinx/transforms/__init__.py8
-rw-r--r--sphinx/transforms/post_transforms/__init__.py13
-rw-r--r--sphinx/util/inspect.py8
9 files changed, 39 insertions, 37 deletions
diff --git a/.flake8 b/.flake8
index 36d126945..a2907a243 100644
--- a/.flake8
+++ b/.flake8
@@ -13,7 +13,6 @@ ignore =
SIM102,
SIM103,
SIM105,
- SIM110,
SIM113,
SIM114,
SIM115,
diff --git a/pyproject.toml b/pyproject.toml
index fbfe043bd..dc0aa8a6c 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -168,6 +168,7 @@ external = [ # Whitelist for RUF100 unkown code warnings
"E704",
"W291",
"W293",
+ "SIM110",
]
select = [
"E", # pycodestyle
diff --git a/sphinx/builders/linkcheck.py b/sphinx/builders/linkcheck.py
index bdce45c68..8b750df2d 100644
--- a/sphinx/builders/linkcheck.py
+++ b/sphinx/builders/linkcheck.py
@@ -382,11 +382,11 @@ class HyperlinkAvailabilityCheckWorker(Thread):
return 'redirected', new_url, 0
def allowed_redirect(url: str, new_url: str) -> bool:
- for from_url, to_url in self.config.linkcheck_allowed_redirects.items():
- if from_url.match(url) and to_url.match(new_url):
- return True
-
- return False
+ return any(
+ from_url.match(url) and to_url.match(new_url)
+ for from_url, to_url
+ in self.config.linkcheck_allowed_redirects.items()
+ )
def check(docname: str) -> tuple[str, str, int]:
# check for various conditions without bothering the network
diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py
index 8a4808c3b..c9367b465 100644
--- a/sphinx/ext/apidoc.py
+++ b/sphinx/ext/apidoc.py
@@ -48,10 +48,10 @@ template_dir = path.join(package_dir, 'templates', 'apidoc')
def is_initpy(filename: str) -> bool:
"""Check *filename* is __init__ file or not."""
basename = path.basename(filename)
- for suffix in sorted(PY_SUFFIXES, key=len, reverse=True):
- if basename == '__init__' + suffix:
- return True
- return False
+ return any(
+ basename == '__init__' + suffix
+ for suffix in sorted(PY_SUFFIXES, key=len, reverse=True)
+ )
def module_join(*modnames: str) -> str:
@@ -225,11 +225,10 @@ def walk(rootpath: str, excludes: list[str], opts: Any
def has_child_module(rootpath: str, excludes: list[str], opts: Any) -> bool:
"""Check the given directory contains child module/s (at least one)."""
- for _root, _subs, files in walk(rootpath, excludes, opts):
- if files:
- return True
-
- return False
+ return any(
+ files
+ for _root, _subs, files in walk(rootpath, excludes, opts)
+ )
def recurse_tree(rootpath: str, excludes: list[str], opts: Any,
@@ -292,10 +291,10 @@ def is_excluded(root: str, excludes: list[str]) -> bool:
Note: by having trailing slashes, we avoid common prefix issues, like
e.g. an exclude "foo" also accidentally excluding "foobar".
"""
- for exclude in excludes:
- if fnmatch(root, exclude):
- return True
- return False
+ return any(
+ fnmatch(root, exclude)
+ for exclude in excludes
+ )
def get_parser() -> argparse.ArgumentParser:
diff --git a/sphinx/ext/coverage.py b/sphinx/ext/coverage.py
index 362a644f5..6c70d4112 100644
--- a/sphinx/ext/coverage.py
+++ b/sphinx/ext/coverage.py
@@ -130,10 +130,10 @@ class CoverageBuilder(Builder):
op.write('\n')
def ignore_pyobj(self, full_name: str) -> bool:
- for exp in self.py_ignorexps:
- if exp.search(full_name):
- return True
- return False
+ return any(
+ exp.search(full_name)
+ for exp in self.py_ignorexps
+ )
def build_py_coverage(self) -> None:
objects = self.env.domaindata['py']['objects']
diff --git a/sphinx/ext/napoleon/docstring.py b/sphinx/ext/napoleon/docstring.py
index 8594cdfc3..0335ec4f8 100644
--- a/sphinx/ext/napoleon/docstring.py
+++ b/sphinx/ext/napoleon/docstring.py
@@ -536,7 +536,7 @@ class GoogleDocstring:
return [(' ' * n) + line for line in lines]
def _is_indented(self, line: str, indent: int = 1) -> bool:
- for i, s in enumerate(line):
+ for i, s in enumerate(line): # noqa: SIM110
if i >= indent:
return True
elif not s.isspace():
diff --git a/sphinx/transforms/__init__.py b/sphinx/transforms/__init__.py
index 3bb1d7b2e..83c2e25fc 100644
--- a/sphinx/transforms/__init__.py
+++ b/sphinx/transforms/__init__.py
@@ -333,10 +333,10 @@ class SphinxSmartQuotes(SmartQuotes, SphinxTransform):
# confirm selected language supports smart_quotes or not
language = self.env.settings['language_code']
- for tag in normalize_language_tag(language):
- if tag in smartchars.quotes:
- return True
- return False
+ return any(
+ tag in smartchars.quotes
+ for tag in normalize_language_tag(language)
+ )
def get_tokens(self, txtnodes: list[Text]) -> Generator[tuple[str, str], None, None]:
# A generator that yields ``(texttype, nodetext)`` tuples for a list
diff --git a/sphinx/transforms/post_transforms/__init__.py b/sphinx/transforms/post_transforms/__init__.py
index 3df68b684..2fabf509a 100644
--- a/sphinx/transforms/post_transforms/__init__.py
+++ b/sphinx/transforms/post_transforms/__init__.py
@@ -180,11 +180,14 @@ class ReferencesResolver(SphinxPostTransform):
warn = False
if self.config.nitpick_ignore_regex:
def matches_ignore(entry_type: str, entry_target: str) -> bool:
- for ignore_type, ignore_target in self.config.nitpick_ignore_regex:
- if re.fullmatch(ignore_type, entry_type) and \
- re.fullmatch(ignore_target, entry_target):
- return True
- return False
+ return any(
+ (
+ re.fullmatch(ignore_type, entry_type)
+ and re.fullmatch(ignore_target, entry_target)
+ )
+ for ignore_type, ignore_target
+ in self.config.nitpick_ignore_regex
+ )
if matches_ignore(dtype, target):
warn = False
# for "std" types also try without domain name
diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py
index 10673ca57..8bea91e96 100644
--- a/sphinx/util/inspect.py
+++ b/sphinx/util/inspect.py
@@ -220,10 +220,10 @@ def isstaticmethod(obj: Any, cls: Any = None, name: str | None = None) -> bool:
def isdescriptor(x: Any) -> bool:
"""Check if the object is some kind of descriptor."""
- for item in '__get__', '__set__', '__delete__':
- if callable(safe_getattr(x, item, None)):
- return True
- return False
+ return any(
+ callable(safe_getattr(x, item, None))
+ for item in ['__get__', '__set__', '__delete__']
+ )
def isabstractmethod(obj: Any) -> bool: