Skip to content

Commit f0d77cd

Browse files
committed
fix: correct merging of options and auto in blueprint
1 parent 1b5cdec commit f0d77cd

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

quartodoc/builder/blueprint.py

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@
2929

3030
from .utils import PydanticTransformer, ctx_node, WorkaroundKeyError
3131

32-
from typing import overload
32+
from typing import overload, TYPE_CHECKING
33+
3334

3435
_log = logging.getLogger(__name__)
3536

37+
if TYPE_CHECKING:
38+
from pydantic import BaseModel
39+
3640

3741
def _auto_package(mod: dc.Module) -> list[Section]:
3842
"""Create default sections for the given package."""
@@ -86,13 +90,24 @@ def _is_external_alias(obj: dc.Alias | dc.Object, mod: dc.Module):
8690
return False
8791

8892

89-
def _to_simple_dict(el):
93+
def _to_simple_dict(el: "BaseModel"):
9094
# round-trip to json, so we can take advantage of pydantic
9195
# dumping Enums, etc.. There may be a simple way to do
9296
# this in pydantic v2.
9397
return json.loads(el.json(exclude_unset=True))
9498

9599

100+
def _non_default_entries(el: "BaseModel"):
101+
field_defaults = {mf.name: mf.default for mf in el.__fields__.values()}
102+
set_fields = [
103+
k for k, v in el if field_defaults[k] is not v if not isinstance(v, MISSING)
104+
]
105+
106+
d = el.dict()
107+
108+
return {k: d[k] for k in set_fields}
109+
110+
96111
class BlueprintTransformer(PydanticTransformer):
97112
def __init__(self, get_object=None, parser="numpy"):
98113

@@ -232,7 +247,9 @@ def enter(self, el: Auto):
232247
# auto default overrides
233248
if self.options is not None:
234249
# TODO: is this round-tripping guaranteed by pydantic?
235-
el = el.__class__(**{**self.options.dict(), **el.dict()})
250+
_option_dict = _non_default_entries(self.options)
251+
_el_dict = _non_default_entries(el)
252+
el = el.__class__(**{**_option_dict, **_el_dict})
236253

237254
# fetching object ----
238255
_log.info(f"Getting object for {path}")

0 commit comments

Comments
 (0)