mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use `any
` to find elements in iterable (#11053)
This commit is contained in:
parent
da6a20d50b
commit
2759c2c76b
1
.flake8
1
.flake8
@ -13,7 +13,6 @@ ignore =
|
|||||||
SIM102,
|
SIM102,
|
||||||
SIM103,
|
SIM103,
|
||||||
SIM105,
|
SIM105,
|
||||||
SIM110,
|
|
||||||
SIM113,
|
SIM113,
|
||||||
SIM114,
|
SIM114,
|
||||||
SIM115,
|
SIM115,
|
||||||
|
@ -168,6 +168,7 @@ external = [ # Whitelist for RUF100 unkown code warnings
|
|||||||
"E704",
|
"E704",
|
||||||
"W291",
|
"W291",
|
||||||
"W293",
|
"W293",
|
||||||
|
"SIM110",
|
||||||
]
|
]
|
||||||
select = [
|
select = [
|
||||||
"E", # pycodestyle
|
"E", # pycodestyle
|
||||||
|
@ -382,11 +382,11 @@ class HyperlinkAvailabilityCheckWorker(Thread):
|
|||||||
return 'redirected', new_url, 0
|
return 'redirected', new_url, 0
|
||||||
|
|
||||||
def allowed_redirect(url: str, new_url: str) -> bool:
|
def allowed_redirect(url: str, new_url: str) -> bool:
|
||||||
for from_url, to_url in self.config.linkcheck_allowed_redirects.items():
|
return any(
|
||||||
if from_url.match(url) and to_url.match(new_url):
|
from_url.match(url) and to_url.match(new_url)
|
||||||
return True
|
for from_url, to_url
|
||||||
|
in self.config.linkcheck_allowed_redirects.items()
|
||||||
return False
|
)
|
||||||
|
|
||||||
def check(docname: str) -> tuple[str, str, int]:
|
def check(docname: str) -> tuple[str, str, int]:
|
||||||
# check for various conditions without bothering the network
|
# check for various conditions without bothering the network
|
||||||
|
@ -48,10 +48,10 @@ template_dir = path.join(package_dir, 'templates', 'apidoc')
|
|||||||
def is_initpy(filename: str) -> bool:
|
def is_initpy(filename: str) -> bool:
|
||||||
"""Check *filename* is __init__ file or not."""
|
"""Check *filename* is __init__ file or not."""
|
||||||
basename = path.basename(filename)
|
basename = path.basename(filename)
|
||||||
for suffix in sorted(PY_SUFFIXES, key=len, reverse=True):
|
return any(
|
||||||
if basename == '__init__' + suffix:
|
basename == '__init__' + suffix
|
||||||
return True
|
for suffix in sorted(PY_SUFFIXES, key=len, reverse=True)
|
||||||
return False
|
)
|
||||||
|
|
||||||
|
|
||||||
def module_join(*modnames: str) -> str:
|
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:
|
def has_child_module(rootpath: str, excludes: list[str], opts: Any) -> bool:
|
||||||
"""Check the given directory contains child module/s (at least one)."""
|
"""Check the given directory contains child module/s (at least one)."""
|
||||||
for _root, _subs, files in walk(rootpath, excludes, opts):
|
return any(
|
||||||
if files:
|
files
|
||||||
return True
|
for _root, _subs, files in walk(rootpath, excludes, opts)
|
||||||
|
)
|
||||||
return False
|
|
||||||
|
|
||||||
|
|
||||||
def recurse_tree(rootpath: str, excludes: list[str], opts: Any,
|
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
|
Note: by having trailing slashes, we avoid common prefix issues, like
|
||||||
e.g. an exclude "foo" also accidentally excluding "foobar".
|
e.g. an exclude "foo" also accidentally excluding "foobar".
|
||||||
"""
|
"""
|
||||||
for exclude in excludes:
|
return any(
|
||||||
if fnmatch(root, exclude):
|
fnmatch(root, exclude)
|
||||||
return True
|
for exclude in excludes
|
||||||
return False
|
)
|
||||||
|
|
||||||
|
|
||||||
def get_parser() -> argparse.ArgumentParser:
|
def get_parser() -> argparse.ArgumentParser:
|
||||||
|
@ -130,10 +130,10 @@ class CoverageBuilder(Builder):
|
|||||||
op.write('\n')
|
op.write('\n')
|
||||||
|
|
||||||
def ignore_pyobj(self, full_name: str) -> bool:
|
def ignore_pyobj(self, full_name: str) -> bool:
|
||||||
for exp in self.py_ignorexps:
|
return any(
|
||||||
if exp.search(full_name):
|
exp.search(full_name)
|
||||||
return True
|
for exp in self.py_ignorexps
|
||||||
return False
|
)
|
||||||
|
|
||||||
def build_py_coverage(self) -> None:
|
def build_py_coverage(self) -> None:
|
||||||
objects = self.env.domaindata['py']['objects']
|
objects = self.env.domaindata['py']['objects']
|
||||||
|
@ -536,7 +536,7 @@ class GoogleDocstring:
|
|||||||
return [(' ' * n) + line for line in lines]
|
return [(' ' * n) + line for line in lines]
|
||||||
|
|
||||||
def _is_indented(self, line: str, indent: int = 1) -> bool:
|
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:
|
if i >= indent:
|
||||||
return True
|
return True
|
||||||
elif not s.isspace():
|
elif not s.isspace():
|
||||||
|
@ -333,10 +333,10 @@ class SphinxSmartQuotes(SmartQuotes, SphinxTransform):
|
|||||||
|
|
||||||
# confirm selected language supports smart_quotes or not
|
# confirm selected language supports smart_quotes or not
|
||||||
language = self.env.settings['language_code']
|
language = self.env.settings['language_code']
|
||||||
for tag in normalize_language_tag(language):
|
return any(
|
||||||
if tag in smartchars.quotes:
|
tag in smartchars.quotes
|
||||||
return True
|
for tag in normalize_language_tag(language)
|
||||||
return False
|
)
|
||||||
|
|
||||||
def get_tokens(self, txtnodes: list[Text]) -> Generator[tuple[str, str], None, None]:
|
def get_tokens(self, txtnodes: list[Text]) -> Generator[tuple[str, str], None, None]:
|
||||||
# A generator that yields ``(texttype, nodetext)`` tuples for a list
|
# A generator that yields ``(texttype, nodetext)`` tuples for a list
|
||||||
|
@ -180,11 +180,14 @@ class ReferencesResolver(SphinxPostTransform):
|
|||||||
warn = False
|
warn = False
|
||||||
if self.config.nitpick_ignore_regex:
|
if self.config.nitpick_ignore_regex:
|
||||||
def matches_ignore(entry_type: str, entry_target: str) -> bool:
|
def matches_ignore(entry_type: str, entry_target: str) -> bool:
|
||||||
for ignore_type, ignore_target in self.config.nitpick_ignore_regex:
|
return any(
|
||||||
if re.fullmatch(ignore_type, entry_type) and \
|
(
|
||||||
re.fullmatch(ignore_target, entry_target):
|
re.fullmatch(ignore_type, entry_type)
|
||||||
return True
|
and re.fullmatch(ignore_target, entry_target)
|
||||||
return False
|
)
|
||||||
|
for ignore_type, ignore_target
|
||||||
|
in self.config.nitpick_ignore_regex
|
||||||
|
)
|
||||||
if matches_ignore(dtype, target):
|
if matches_ignore(dtype, target):
|
||||||
warn = False
|
warn = False
|
||||||
# for "std" types also try without domain name
|
# for "std" types also try without domain name
|
||||||
|
@ -220,10 +220,10 @@ def isstaticmethod(obj: Any, cls: Any = None, name: str | None = None) -> bool:
|
|||||||
|
|
||||||
def isdescriptor(x: Any) -> bool:
|
def isdescriptor(x: Any) -> bool:
|
||||||
"""Check if the object is some kind of descriptor."""
|
"""Check if the object is some kind of descriptor."""
|
||||||
for item in '__get__', '__set__', '__delete__':
|
return any(
|
||||||
if callable(safe_getattr(x, item, None)):
|
callable(safe_getattr(x, item, None))
|
||||||
return True
|
for item in ['__get__', '__set__', '__delete__']
|
||||||
return False
|
)
|
||||||
|
|
||||||
|
|
||||||
def isabstractmethod(obj: Any) -> bool:
|
def isabstractmethod(obj: Any) -> bool:
|
||||||
|
Loading…
Reference in New Issue
Block a user