From cdb239ada382738eb99206825a635b09bdb981da Mon Sep 17 00:00:00 2001 From: Ghislain Vaillant Date: Thu, 10 Aug 2023 11:59:26 +0200 Subject: [PATCH] DOC: Sync sphinxext with upstream --- docs/sphinxext/github_link.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/docs/sphinxext/github_link.py b/docs/sphinxext/github_link.py index d30186c70c..afce4e2883 100644 --- a/docs/sphinxext/github_link.py +++ b/docs/sphinxext/github_link.py @@ -2,12 +2,12 @@ This script comes from scikit-learn: https://github.com/scikit-learn/scikit-learn/blob/master/doc/sphinxext/github_link.py """ -from operator import attrgetter import inspect -import subprocess import os +import subprocess import sys from functools import partial +from operator import attrgetter REVISION_CMD = "git rev-parse --short HEAD" @@ -44,14 +44,12 @@ def _linkcode_resolve(domain, info, package, url_fmt, revision): return class_name = info["fullname"].split(".")[0] - if type(class_name) != str: - # Python 2 only - class_name = class_name.encode("utf-8") module = __import__(info["module"], fromlist=[class_name]) - try: - obj = attrgetter(info["fullname"])(module) - except AttributeError: - return + obj = attrgetter(info["fullname"])(module) + + # Unwrap the object to get the correct source + # file in case that is wrapped by a decorator + obj = inspect.unwrap(obj) try: fn = inspect.getsourcefile(obj)