Skip to content

Commit

Permalink
fix: Don't trigger alias resolution when merging stubs
Browse files Browse the repository at this point in the history
Issue #89: #89
  • Loading branch information
pawamoy committed Jun 25, 2022
1 parent f212dd3 commit 2b88627
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/griffe/merger.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ def _merge_stubs_members(obj: Module | Class, stubs: Module | Class) -> None: #
for member_name, stub_member in stubs.members.items():
if member_name in obj.members:
obj_member = obj[member_name]
if obj_member.is_alias:
continue
if obj_member.kind is not stub_member.kind:
logger.debug(f"Cannot merge stubs of kind {stub_member.kind} into object of kind {obj_member.kind}")
elif obj_member.is_class:
Expand Down
32 changes: 32 additions & 0 deletions tests/test_merger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Tests for the `merger` module."""

from textwrap import dedent

from griffe.loader import GriffeLoader
from tests.helpers import temporary_pypackage


def test_dont_trigger_alias_resolution_when_merging_stubs():
"""Assert that we don't trigger alias resolution when merging stubs."""
with temporary_pypackage("package", ["mod.py", "mod.pyi"]) as tmp_package:
tmp_package.path.joinpath("mod.py").write_text(
dedent(
"""
import pathlib
def f() -> pathlib.Path:
return pathlib.Path()
"""
)
)
tmp_package.path.joinpath("mod.pyi").write_text(
dedent(
"""
import pathlib
def f() -> pathlib.Path: ...
"""
)
)
loader = GriffeLoader(search_paths=[tmp_package.tmpdir])
loader.load_module(tmp_package.name)

0 comments on commit 2b88627

Please sign in to comment.