diff --git a/src/griffe/loader.py b/src/griffe/loader.py index 2bea99b0..3db027d9 100644 --- a/src/griffe/loader.py +++ b/src/griffe/loader.py @@ -210,24 +210,7 @@ def expand_wildcards(self, obj: Object, seen: set | None = None) -> None: # noq del obj[name] # noqa: WPS420 for new_member, alias_lineno, alias_endlineno in expanded: - if new_member.is_alias: - try: - # TODO: maybe don't shortcut aliases: - # we want to keep public paths - alias = Alias( - new_member.name, - new_member.target, # type: ignore[union-attr] - lineno=alias_lineno, - endlineno=alias_endlineno, - ) - except AliasResolutionError: - alias = new_member # type: ignore[assignment] # noqa: WPS437 - except CyclicAliasError as error: # noqa: WPS440 - logger.debug(str(error)) - continue - else: - alias = Alias(new_member.name, new_member, lineno=alias_lineno, endlineno=alias_endlineno) - obj[new_member.name] = alias + obj[new_member.name] = Alias(new_member.name, new_member, lineno=alias_lineno, endlineno=alias_endlineno) def resolve_module_aliases( # noqa: WPS231 self, diff --git a/tests/test_loader.py b/tests/test_loader.py index 712bbe74..12192061 100644 --- a/tests/test_loader.py +++ b/tests/test_loader.py @@ -1,5 +1,6 @@ """Tests for the `loader` module.""" +from griffe.expressions import Name from griffe.loader import GriffeLoader from tests.helpers import temporary_pyfile, temporary_pypackage @@ -41,3 +42,25 @@ def test_recursive_wildcard_expansion(): assert "CONST_Y" in package["mod_a"].members assert "CONST_X" in package["mod_a.mod_b"].members assert "CONST_Y" in package["mod_a.mod_b"].members + + +def test_dont_shortcut_alias_chain_after_expanding_wildcards(): + """Assert public aliases paths are not resolved to canonical paths when expanding wildcards.""" + with temporary_pypackage("package", ["mod_a.py", "mod_b.py", "mod_c.py"]) as tmp_package: + mod_a = tmp_package.path / "mod_a.py" + mod_b = tmp_package.path / "mod_b.py" + mod_c = tmp_package.path / "mod_c.py" + + mod_a.write_text("from package.mod_b import *\nclass Child(Base): ...\n") + mod_b.write_text("from package.mod_c import Base\n__all__ = ['Base']\n") + mod_c.write_text("class Base: ...\n") + + loader = GriffeLoader(search_paths=[tmp_package.tmpdir]) + package = loader.load_module(tmp_package.name) + loader.resolve_aliases(package) + child = package["mod_a.Child"] + assert child.bases + base = child.bases[0] + assert isinstance(base, Name) + assert base.source == "Base" + assert base.full == "package.mod_b.Base"