Skip to content

Commit b940c51

Browse files
committed
fix: Override attribute values when merging stubs
Issue-mkdocstrings-751: mkdocstrings/mkdocstrings#751
1 parent 0e7c55b commit b940c51

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

src/_griffe/merger.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ def _merge_function_stubs(function: Function, stubs: Function) -> None:
3535
def _merge_attribute_stubs(attribute: Attribute, stubs: Attribute) -> None:
3636
_merge_stubs_docstring(attribute, stubs)
3737
attribute.annotation = stubs.annotation
38+
if stubs.value not in (None, "..."):
39+
attribute.value = stubs.value
3840

3941

4042
def _merge_stubs_docstring(obj: Object, stubs: Object) -> None:

tests/test_merger.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,3 +47,16 @@ def test_merge_imports() -> None:
4747
},
4848
) as pkg:
4949
assert set(pkg["mod"].imports) == {"abc", "collections"}
50+
51+
52+
def test_merge_attribute_values() -> None:
53+
"""Assert that attribute values are merged correctly."""
54+
with temporary_visited_package(
55+
"package",
56+
{
57+
"__init__.py": "import dynamic_all\n__all__ = dynamic_all()",
58+
"__init__.pyi": "from ._hello import hello\n__all__ = ['hello']",
59+
"_hello.py": "def hello() -> None:\n '''Say hello.'''",
60+
},
61+
) as pkg:
62+
assert str(pkg["__all__"].value) == "['hello']"

0 commit comments

Comments
 (0)