From ea38d9629832b33420b3700e7fdf21fd67fabf75 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Fri, 12 Nov 2021 00:44:03 +0900 Subject: [PATCH] Fix #9838: autodoc: AttributeError is raised for lru_cache --- CHANGES | 3 +++ sphinx/util/inspect.py | 13 +++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 81e2ebf64cd..4ee8d55cd91 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,9 @@ Features added Bugs fixed ---------- +* #9838: autodoc: AttributeError is raised on building document for functions + decorated by functools.lru_cache + Testing -------- diff --git a/sphinx/util/inspect.py b/sphinx/util/inspect.py index 7e45fe32226..3a39bde1d6b 100644 --- a/sphinx/util/inspect.py +++ b/sphinx/util/inspect.py @@ -19,8 +19,7 @@ import warnings from functools import partial, partialmethod from importlib import import_module -from inspect import (Parameter, isasyncgenfunction, isclass, ismethod, # NOQA - ismethoddescriptor, ismodule) +from inspect import Parameter, isclass, ismethod, ismethoddescriptor, ismodule # NOQA from io import StringIO from types import ModuleType from typing import Any, Callable, Dict, Mapping, Optional, Sequence, Tuple, Type, cast @@ -408,6 +407,16 @@ def iswrappedcoroutine(obj: Any) -> bool: return False +def isasyncgenfunction(obj: Any) -> bool: + """Check if the object is async-gen function.""" + if hasattr(obj, '__code__') and inspect.isasyncgenfunction(obj): + # check obj.__code__ because isasyncgenfunction() crashes for custom method-like + # objects on python3.7 (see https://github.com/sphinx-doc/sphinx/issues/9838) + return True + else: + return False + + def isproperty(obj: Any) -> bool: """Check if the object is property.""" if sys.version_info >= (3, 8):