Skip to content

Commit

Permalink
add _Base.additional_properties (#34)
Browse files Browse the repository at this point in the history
  • Loading branch information
dsehnal authored Sep 30, 2024
1 parent 34b81f0 commit 3abe0f6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion molviewspec/molviewspec/builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import math
import os
from typing import Sequence
from typing import Sequence, Self

from pydantic import BaseModel, PrivateAttr

Expand Down Expand Up @@ -82,6 +82,18 @@ def _add_child(self, node: Node) -> None:
self._node.children = []
self._node.children.append(node)

def additional_properties(self, **kwargs) -> Self:
"""
Adds provided key-value pairs as additional properties to this node.
key=None to remove a property.
"""
properties = {
**(self._node.additional_properties or {}),
**{k: v for k, v in kwargs.items() if v is not None},
}
self._node = self._node.copy(update={"additional_properties": properties or None})
return self


class Root(_Base):
"""
Expand Down

0 comments on commit 3abe0f6

Please sign in to comment.