@@ -99,6 +99,8 @@ class PythonHandler(BaseHandler):
9999 "members" : None ,
100100 "filters" : ["!^_[^_]" ],
101101 "annotations_path" : "brief" ,
102+ "preload_modules" : None ,
103+ "load_external_modules" : False ,
102104 }
103105 """
104106 Attributes: Headings options:
@@ -150,6 +152,16 @@ class PythonHandler(BaseHandler):
150152 Attributes: Additional options:
151153 show_bases (bool): Show the base classes of a class. Default: `True`.
152154 show_source (bool): Show the source code of this object. Default: `True`.
155+ preload_modules (list[str] | None): Pre-load modules that are
156+ not specified directly in autodoc instructions (`::: identifier`).
157+ It is useful when you want to render documentation for a particular member of an object,
158+ and this member is imported from another package than its parent.
159+
160+ For an imported member to be rendered, you need to add it to the `__all__` attribute
161+ of the importing module.
162+
163+ The modules must be listed as an array of strings. Default: `None`.
164+
153165 """ # noqa: E501
154166
155167 def __init__ (
@@ -235,12 +247,16 @@ def collect(self, identifier: str, config: Mapping[str, Any]) -> CollectorItem:
235247 modules_collection = self ._modules_collection ,
236248 lines_collection = self ._lines_collection ,
237249 )
238- try :
250+ try : # noqa: WPS229 we expect one type of exception, and want to fail on the first one
251+ for pre_loaded_module in final_config .get ("preload_modules" ) or []:
252+ if pre_loaded_module not in self ._modules_collection :
253+ loader .load_module (pre_loaded_module )
239254 loader .load_module (module_name )
240255 except ImportError as error :
241256 raise CollectionError (str (error )) from error
242-
243- unresolved , iterations = loader .resolve_aliases (implicit = False , external = False )
257+ unresolved , iterations = loader .resolve_aliases (
258+ implicit = False , external = final_config ["load_external_modules" ]
259+ )
244260 if unresolved :
245261 logger .debug (f"{ len (unresolved )} aliases were still unresolved after { iterations } iterations" )
246262 logger .debug (f"Unresolved aliases: { ', ' .join (sorted (unresolved ))} " )
0 commit comments