diff options
| author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2020-06-08 22:23:46 +0900 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-06-08 22:23:46 +0900 |
| commit | 23a51a3a33f0003854e08424f8bf6dce2bcaf6b7 (patch) | |
| tree | 1a4f37c534ab080ecfd58588dc7e1f1c4d7a178e /sphinx/ext | |
| parent | d0cdf073bd36aaa050858df510455b145bc2c4bd (diff) | |
| parent | f98987b24ecff3c5d30ecb34ce0c8515132cde87 (diff) | |
| download | sphinx-git-23a51a3a33f0003854e08424f8bf6dce2bcaf6b7.tar.gz | |
Merge pull request #7797 from tk0miya/7791_TypeError_for_singledispatchfunction
Fix #7791: autodoc: TypeError is raised on documenting singledispatch function
Diffstat (limited to 'sphinx/ext')
| -rw-r--r-- | sphinx/ext/autodoc/__init__.py | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/sphinx/ext/autodoc/__init__.py b/sphinx/ext/autodoc/__init__.py index 09db26948..06961d1f8 100644 --- a/sphinx/ext/autodoc/__init__.py +++ b/sphinx/ext/autodoc/__init__.py @@ -1222,7 +1222,15 @@ class FunctionDocumenter(DocstringSignatureMixin, ModuleLevelDocumenter): # typ def annotate_to_first_argument(self, func: Callable, typ: Type) -> None: """Annotate type hint to the first argument of function if needed.""" - sig = inspect.signature(func) + try: + sig = inspect.signature(func) + except TypeError as exc: + logger.warning(__("Failed to get a function signature for %s: %s"), + self.fullname, exc) + return + except ValueError: + return + if len(sig.parameters) == 0: return @@ -1811,7 +1819,14 @@ class MethodDocumenter(DocstringSignatureMixin, ClassLevelDocumenter): # type: def annotate_to_first_argument(self, func: Callable, typ: Type) -> None: """Annotate type hint to the first argument of function if needed.""" - sig = inspect.signature(func) + try: + sig = inspect.signature(func) + except TypeError as exc: + logger.warning(__("Failed to get a method signature for %s: %s"), + self.fullname, exc) + return + except ValueError: + return if len(sig.parameters) == 1: return |
