mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Fix #7812: autosummary: generates broken stub files
This commit is contained in:
parent
eff48a9dac
commit
d8cf26ef93
3
CHANGES
3
CHANGES
@ -16,6 +16,9 @@ Features added
|
||||
Bugs fixed
|
||||
----------
|
||||
|
||||
* #7812: autosummary: generates broken stub files if the target code contains
|
||||
an attribute and module that are same name
|
||||
|
||||
Testing
|
||||
--------
|
||||
|
||||
|
@ -615,13 +615,28 @@ def split_full_qualified_name(name: str) -> Tuple[str, str]:
|
||||
Therefore you need to mock 3rd party modules if needed before
|
||||
calling this function.
|
||||
"""
|
||||
from sphinx.util import inspect
|
||||
|
||||
parts = name.split('.')
|
||||
for i, part in enumerate(parts, 1):
|
||||
try:
|
||||
modname = ".".join(parts[:i])
|
||||
import_module(modname)
|
||||
module = import_module(modname)
|
||||
|
||||
# check the module has a member named as attrname
|
||||
#
|
||||
# Note: This is needed to detect the attribute having the same name
|
||||
# as the module.
|
||||
# ref: https://github.com/sphinx-doc/sphinx/issues/7812
|
||||
attrname = parts[i]
|
||||
if hasattr(module, attrname):
|
||||
value = inspect.safe_getattr(module, attrname)
|
||||
if not inspect.ismodule(value):
|
||||
return ".".join(parts[:i]), ".".join(parts[i:])
|
||||
except ImportError:
|
||||
return ".".join(parts[:i - 1]), ".".join(parts[i - 1:])
|
||||
except IndexError:
|
||||
pass
|
||||
|
||||
return name, ""
|
||||
|
||||
|
@ -18,7 +18,7 @@ import typing
|
||||
import warnings
|
||||
from functools import partial, partialmethod
|
||||
from inspect import ( # NOQA
|
||||
Parameter, isclass, ismethod, ismethoddescriptor
|
||||
Parameter, isclass, ismethod, ismethoddescriptor, ismodule
|
||||
)
|
||||
from io import StringIO
|
||||
from typing import Any, Callable, Mapping, List, Optional, Tuple
|
||||
|
Loading…
Reference in New Issue
Block a user