Skip to content

Commit 24a10f7

Browse files
fix: Don't process class aliases, as real classes are processed at some point anyway
Processing the alias skips the real class later, which prevents the extension from seeing model fields. Issue-8: #8 PR-7: #7 Co-authored-by: Timothée Mazzucotelli <[email protected]>
1 parent 3156504 commit 24a10f7

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/griffe_pydantic/static.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,9 @@ def process_module(
162162
processed.add(mod.canonical_path)
163163

164164
for cls in mod.classes.values():
165-
process_class(cls, processed=processed, schema=schema)
165+
# Don't process aliases, real classes will be processed at some point anyway.
166+
if not cls.is_alias:
167+
process_class(cls, processed=processed, schema=schema)
166168

167169
for submodule in mod.modules.values():
168170
process_module(submodule, processed=processed, schema=schema)

tests/test_extension.py

+14
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,17 @@ def test_extension() -> None:
7070

7171
schema = package.classes["ExampleModel"].extra["griffe_pydantic"]["schema"]
7272
assert schema.startswith('{\n "description"')
73+
74+
75+
def test_imported_models() -> None:
76+
"""Test the extension with imported models."""
77+
with temporary_visited_package(
78+
"package",
79+
modules={
80+
"__init__.py": "from ._private import MyModel\n\n__all__ = ['MyModel']",
81+
"_private.py": "from pydantic import BaseModel\n\nclass MyModel(BaseModel):\n field1: str\n '''Some field.'''\n",
82+
},
83+
extensions=Extensions(PydanticExtension(schema=True)),
84+
) as package:
85+
assert package["MyModel"].labels == {"pydantic-model"}
86+
assert package["MyModel.field1"].labels == {"pydantic-field"}

0 commit comments

Comments
 (0)