mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Address SIM103 lints (#11052)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
This commit is contained in:
parent
dbf36f8b37
commit
cc8f697a9b
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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:
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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):
|
||||
|
@ -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:
|
||||
|
@ -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.<locals>.new_type':
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
return __module__ == 'typing' and __qualname__ == 'NewType.<locals>.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:
|
||||
|
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user