-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Describe the bug
According to https://www.sphinx-doc.org/en/master/extdev/deprecated.html, sphinx.util.import_object
is deprecated and importlib.import_module
is suggested as alternative.
However, sphinx.util.import_object
, does much more:
sphinx/sphinx/util/_importer.py
Lines 9 to 27 in 116a430
def import_object(object_name: str, /, source: str = '') -> Any: | |
"""Import python object by qualname.""" | |
obj_path = object_name.split('.') | |
module_name = obj_path.pop(0) | |
try: | |
obj = import_module(module_name) | |
for name in obj_path: | |
module_name += '.' + name | |
try: | |
obj = getattr(obj, name) | |
except AttributeError: | |
obj = import_module(module_name) | |
except (AttributeError, ImportError) as exc: | |
if source: | |
msg = f'Could not import {object_name} (needed for {source})' | |
raise ExtensionError(msg, exc) from exc | |
msg = f'Could not import {object_name}' | |
raise ExtensionError(msg, exc) from exc | |
return obj |
Am I supposed to copy all that code into my extension?
Or is there another (shorter) replacement?
Either way, this information should be added to the docs.
How to Reproduce
-
Use
sphinx.util.import_object()
. This will give a warning:sphinx.deprecation.RemovedInSphinx10Warning: 'sphinx.util.import_object' is deprecated. Check CHANGES for Sphinx API modifications.
-
Look for
CHANGES
-> not found -
try CHANGES.rst -> the relevant content isn't there
-
try doc/changes/8.1.rst ->
importlib.import_module
is suggested -
use
importlib.import_module
-> doesn't work, because it provides only a small part of original functionality
Environment Information
-
Sphinx extensions
No response
Additional context
No response