Skip to content

Commit

Permalink
Merge pull request #9840 from tk0miya/9838_isasyncgenfunction
Browse files Browse the repository at this point in the history
Fix #9838: autodoc: AttributeError is raised for lru_cache
  • Loading branch information
tk0miya committed Nov 16, 2021
2 parents 9d68c6b + ea38d96 commit ab232e9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Expand Up @@ -40,6 +40,9 @@ Features added
Bugs fixed
----------

* #9838: autodoc: AttributeError is raised on building document for functions
decorated by functools.lru_cache

Testing
--------

Expand Down
13 changes: 11 additions & 2 deletions sphinx/util/inspect.py
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit ab232e9

Please sign in to comment.