Skip to content

Commit

Permalink
Merge pull request #10081 from danieleades/refactor/callable-test
Browse files Browse the repository at this point in the history
use 'callable' to check if object is callable (B004)
  • Loading branch information
tk0miya committed Jan 10, 2022
2 parents b5f4d2d + 61ff904 commit e79681c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions sphinx/config.py
Expand Up @@ -206,7 +206,7 @@ def convert_overrides(self, name: str, value: Any) -> Any:
except ValueError as exc:
raise ValueError(__('invalid number %r for config value %r, ignoring') %
(value, name)) from exc
elif hasattr(defvalue, '__call__'):
elif callable(defvalue):
return value
elif defvalue is not None and not isinstance(defvalue, str):
raise ValueError(__('cannot override config setting %r with unsupported '
Expand Down Expand Up @@ -257,7 +257,7 @@ def __getattr__(self, name: str) -> Any:
if name not in self.values:
raise AttributeError(__('No such config value: %s') % name)
default = self.values[name][0]
if hasattr(default, '__call__'):
if callable(default):
return default(self)
return default

Expand Down Expand Up @@ -413,7 +413,7 @@ def check_confval_types(app: "Sphinx", config: Config) -> None:
for confval in config:
default, rebuild, annotations = config.values[confval.name]

if hasattr(default, '__call__'):
if callable(default):
default = default(config) # evaluate default value
if default is None and not annotations:
continue # neither inferable nor expliclitly annotated types
Expand Down
2 changes: 1 addition & 1 deletion sphinx/util/inspect.py
Expand Up @@ -301,7 +301,7 @@ def isstaticmethod(obj: Any, cls: Any = None, name: str = None) -> bool:
def isdescriptor(x: Any) -> bool:
"""Check if the object is some kind of descriptor."""
for item in '__get__', '__set__', '__delete__':
if hasattr(safe_getattr(x, item, None), '__call__'):
if callable(safe_getattr(x, item, None)):
return True
return False

Expand Down
2 changes: 1 addition & 1 deletion tests/test_build_html.py
Expand Up @@ -99,7 +99,7 @@ def check_xpath(etree, fname, path, check, be_found=True):
else:
assert nodes != [], ('did not find any node matching xpath '
'%r in file %s' % (path, fname))
if hasattr(check, '__call__'):
if callable(check):
check(nodes)
elif not check:
# only check for node presence
Expand Down

0 comments on commit e79681c

Please sign in to comment.