diff --git a/sphinx/builders/html/transforms.py b/sphinx/builders/html/transforms.py index eac23a92e..f7edecde4 100644 --- a/sphinx/builders/html/transforms.py +++ b/sphinx/builders/html/transforms.py @@ -69,10 +69,7 @@ class KeyboardTransform(SphinxPostTransform): def is_multiwords_key(self, parts: list[str]) -> bool: if len(parts) >= 3 and parts[1].strip() == '': name = parts[0].lower(), parts[2].lower() - if name in self.multiwords_keys: - return True - else: - return False + return name in self.multiwords_keys else: return False diff --git a/sphinx/cmd/quickstart.py b/sphinx/cmd/quickstart.py index 0e714538e..0282eb827 100644 --- a/sphinx/cmd/quickstart.py +++ b/sphinx/cmd/quickstart.py @@ -174,10 +174,7 @@ class QuickstartRenderer(SphinxRenderer): It will be removed in the future without deprecation period. """ template = path.join(self.templatedir, path.basename(template_name)) - if self.templatedir and path.exists(template): - return True - else: - return False + return bool(self.templatedir) and path.exists(template) def render(self, template_name: str, context: dict[str, Any]) -> str: if self._has_custom_template(template_name): diff --git a/sphinx/ext/apidoc.py b/sphinx/ext/apidoc.py index c9367b465..2e5079681 100644 --- a/sphinx/ext/apidoc.py +++ b/sphinx/ext/apidoc.py @@ -179,11 +179,7 @@ def is_skipped_package(dirname: str, opts: Any, excludes: list[str] = []) -> boo return True # Check there is some showable module inside package - if all(is_excluded(path.join(dirname, f), excludes) for f in files): - # all submodules are excluded - return True - else: - return False + return all(is_excluded(path.join(dirname, f), excludes) for f in files) def is_skipped_module(filename: str, opts: Any, excludes: list[str]) -> bool: diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 35b16673e..d9c0cd09a 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -2353,10 +2353,7 @@ class SlotsMixin(DataDocumenterMixinBase): """Check the subject is an attribute in __slots__.""" try: __slots__ = inspect.getslots(self.parent) - if __slots__ and self.objpath[-1] in __slots__: - return True - else: - return False + return bool(__slots__) and self.objpath[-1] in __slots__ except (ValueError, TypeError): return False @@ -2484,10 +2481,7 @@ class UninitializedInstanceAttributeMixin(DataDocumenterMixinBase): def is_uninitialized_instance_attribute(self, parent: Any) -> bool: """Check the subject is an annotation only attribute.""" annotations = get_type_hints(parent, None, self.config.autodoc_type_aliases) - if self.objpath[-1] in annotations: - return True - else: - return False + return self.objpath[-1] in annotations def import_object(self, raiseerror: bool = False) -> bool: """Check the exisitence of uninitialized instance attribute when failed to import diff --git a/sphinx/ext/intersphinx.py b/sphinx/ext/intersphinx.py index f501867ff..9e69d053c 100644 --- a/sphinx/ext/intersphinx.py +++ b/sphinx/ext/intersphinx.py @@ -547,10 +547,7 @@ class IntersphinxRole(SphinxRole): def is_existent_role(self, domain_name: str, role_name: str) -> bool: try: domain = self.env.get_domain(domain_name) - if role_name in domain.roles: - return True - else: - return False + return role_name in domain.roles except ExtensionError: return False diff --git a/sphinx/transforms/post_transforms/images.py b/sphinx/transforms/post_transforms/images.py index afb8bfd6d..acf3ba486 100644 --- a/sphinx/transforms/post_transforms/images.py +++ b/sphinx/transforms/post_transforms/images.py @@ -204,10 +204,7 @@ class ImageConverter(BaseImageConverter): return False else: rule = self.get_conversion_rule(node) - if rule: - return True - else: - return False + return bool(rule) def get_conversion_rule(self, node: nodes.image) -> tuple[str, str]: for candidate in self.guess_mimetypes(node): diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index d1fa7734f..07c3c2fad 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -441,10 +441,7 @@ def encode_uri(uri: str) -> str: def isurl(url: str) -> bool: """Check *url* is URL or not.""" - if url and '://' in url: - return True - else: - return False + return bool(url) and '://' in url def display_chunk(chunk: Any) -> str: diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 8bea91e96..7c0a9f066 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -151,10 +151,7 @@ def isNewType(obj: Any) -> bool: else: __module__ = safe_getattr(obj, '__module__', None) __qualname__ = safe_getattr(obj, '__qualname__', None) - if __module__ == 'typing' and __qualname__ == 'NewType..new_type': - return True - else: - return False + return __module__ == 'typing' and __qualname__ == 'NewType..new_type' def isenumclass(x: Any) -> bool: @@ -210,10 +207,7 @@ def isstaticmethod(obj: Any, cls: Any = None, name: str | None = None) -> bool: for basecls in getattr(cls, '__mro__', [cls]): meth = basecls.__dict__.get(name) if meth: - if isinstance(meth, staticmethod): - return True - else: - return False + return isinstance(meth, staticmethod) return False @@ -277,13 +271,10 @@ def isattributedescriptor(obj: Any) -> bool: def is_singledispatch_function(obj: Any) -> bool: """Check if the object is singledispatch function.""" - if (inspect.isfunction(obj) and + return (inspect.isfunction(obj) and hasattr(obj, 'dispatch') and hasattr(obj, 'register') and - obj.dispatch.__module__ == 'functools'): - return True - else: - return False + obj.dispatch.__module__ == 'functools') def is_singledispatch_method(obj: Any) -> bool: @@ -314,18 +305,10 @@ def iscoroutinefunction(obj: Any) -> bool: # staticmethod, classmethod and partial method are not a wrapped coroutine-function # Note: Since 3.10, staticmethod and classmethod becomes a kind of wrappers return False - elif hasattr(obj, '__wrapped__'): - return True - else: - return False + return hasattr(obj, '__wrapped__') obj = unwrap_all(obj, stop=iswrappedcoroutine) - if hasattr(obj, '__code__') and inspect.iscoroutinefunction(obj): - # check obj.__code__ because iscoroutinefunction() crashes for custom method-like - # objects (see https://github.com/sphinx-doc/sphinx/issues/6605) - return True - else: - return False + return inspect.iscoroutinefunction(obj) def isproperty(obj: Any) -> bool: diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py index b2ff96854..6804dd3ca 100644 --- a/sphinx/util/logging.py +++ b/sphinx/util/logging.py @@ -353,10 +353,7 @@ class InfoFilter(logging.Filter): """Filter error and warning messages.""" def filter(self, record: logging.LogRecord) -> bool: - if record.levelno < logging.WARNING: - return True - else: - return False + return record.levelno < logging.WARNING def is_suppressed_warning(type: str, subtype: str, suppress_warnings: list[str]) -> bool: