Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add _Base.additional_properties #34

Merged
merged 1 commit into from
Sep 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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