diff options
author | danieleades <33452915+danieleades@users.noreply.github.com> | 2023-01-02 04:52:46 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-01-02 04:52:46 +0000 |
commit | 2759c2c76b5cd09e9dfffbd88ea1b200dcd8d6ae (patch) | |
tree | a1ffe3ce69c2fbf2dd457906622fb6ca6cc08501 /sphinx/ext/apidoc.py | |
parent | da6a20d50b725f6c33f0f940e2a59c9a4e7edc15 (diff) | |
download | sphinx-git-2759c2c76b5cd09e9dfffbd88ea1b200dcd8d6ae.tar.gz |
Use ``any`` to find elements in iterable (#11053)
Diffstat (limited to 'sphinx/ext/apidoc.py')
-rw-r--r-- | sphinx/ext/apidoc.py | 25 |
1 files changed, 12 insertions, 13 deletions
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: |