diff --git a/docs/guide/users/extending.md b/docs/guide/users/extending.md index 509247d6..715fe82d 100644 --- a/docs/guide/users/extending.md +++ b/docs/guide/users/extending.md @@ -190,11 +190,10 @@ There are two kinds of events in Griffe: **load events** and **analysis events** #### Load events -There is only one **load event**: +There are two **load events**: -- [`on_package_loaded`][griffe.Extension.on_package_loaded] - -This event is triggered when the loader has finished loading a package entirely, i.e. when all its submodules were scanned and loaded. This event can be hooked by extensions which require the whole package to be loaded, to be able to navigate the object tree without raising lookup errors or alias resolution errors. +- [`on_package_loaded`][griffe.Extension.on_package_loaded]: The "on package loaded" event is triggered when the loader has finished loading a package entirely, i.e. when all its submodules were scanned and loaded. This event can be hooked by extensions which require the whole package to be loaded, to be able to navigate the object tree without raising lookup errors or alias resolution errors. +- [`on_wildcard_expansion`][griffe.Extension.on_wildcard_expansion]: The "on wildcard expansion" event is triggered for each alias that is created by expanding wildcard imports (`from ... import *`). #### Analysis events diff --git a/src/_griffe/extensions/base.py b/src/_griffe/extensions/base.py index 31b52dc1..1903efe0 100644 --- a/src/_griffe/extensions/base.py +++ b/src/_griffe/extensions/base.py @@ -261,6 +261,21 @@ def on_package_loaded(self, *, pkg: Module, loader: GriffeLoader, **kwargs: Any) **kwargs: For forward-compatibility. """ + def on_wildcard_expansion( + self, + *, + alias: Alias, + loader: GriffeLoader, + **kwargs: Any, + ) -> None: + """Run when wildcard imports are expanded into aliases. + + Parameters: + alias: The alias instance. + loader: The loader currently in use. + **kwargs: For forward-compatibility. + """ + LoadableExtensionType = Union[str, Dict[str, Any], Extension, Type[Extension]] """All the types that can be passed to `load_extensions`.""" diff --git a/src/_griffe/loader.py b/src/_griffe/loader.py index 069e39c4..76e06971 100644 --- a/src/_griffe/loader.py +++ b/src/_griffe/loader.py @@ -399,6 +399,7 @@ def expand_wildcards( # Everything went right (supposedly), we add the alias as a member of the current object. obj.set_member(new_member.name, alias) + self.extensions.call("on_wildcard_expansion", alias=alias, loader=self) def resolve_module_aliases( self,