diff options
author | Daniel Eades <danieleades@hotmail.com> | 2022-01-10 13:51:35 +0000 |
---|---|---|
committer | Daniel Eades <danieleades@hotmail.com> | 2022-01-10 13:51:35 +0000 |
commit | 61ff90460d61a33a9187006fd199424b23e9fbd2 (patch) | |
tree | 7fca648bd26f8665722a5c59f9c1f424c5b5275c | |
parent | 72d352f64ec97c2b15173cc1a191c0e80bde9630 (diff) | |
download | sphinx-git-61ff90460d61a33a9187006fd199424b23e9fbd2.tar.gz |
use 'callable' to check if object is callable (B004)
-rw-r--r-- | sphinx/config.py | 6 | ||||
-rw-r--r-- | sphinx/util/inspect.py | 2 | ||||
-rw-r--r-- | tests/test_build_html.py | 2 |
3 files changed, 5 insertions, 5 deletions
diff --git a/sphinx/config.py b/sphinx/config.py index 38ed1d388..9cce0cc41 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -206,7 +206,7 @@ class Config: 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 ' @@ -257,7 +257,7 @@ class Config: 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 @@ -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 diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 763e39cc2..06920288f 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -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 diff --git a/tests/test_build_html.py b/tests/test_build_html.py index 3a468df4a..2568bb5b8 100644 --- a/tests/test_build_html.py +++ b/tests/test_build_html.py @@ -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 |