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

[#240] making Atom/Node/Link attrs writable #241

Merged
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
30 changes: 17 additions & 13 deletions hyperon_das_atomdb_cpp/src/nanobind/hyperon_das_atomdb_cpp_bind.cc
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,13 @@ NB_MODULE(ext, m) {
// document_types submodule --------------------------------------------------------------------
nb::module_ document_types = m.def_submodule("document_types");
nb::class_<Atom>(document_types, "Atom")
.def_ro("_id", &Atom::_id)
.def_rw("_id", &Atom::_id)
.def_prop_ro("id", // read-only property for having access to `_id` as `id`
[](const Atom& self) -> string { return self._id; })
.def_ro("handle", &Atom::handle)
.def_ro("composite_type_hash", &Atom::composite_type_hash)
.def_ro("named_type", &Atom::named_type)
.def_ro("custom_attributes", &Atom::custom_attributes)
.def_rw("handle", &Atom::handle)
.def_rw("composite_type_hash", &Atom::composite_type_hash)
.def_rw("named_type", &Atom::named_type)
.def_rw("custom_attributes", &Atom::custom_attributes)
.def("to_string", &Atom::to_string)
.def("__str__", &Atom::to_string)
.def("__repr__", &Atom::to_string)
Expand Down Expand Up @@ -320,7 +320,7 @@ NB_MODULE(ext, m) {
"named_type"_a,
"name"_a,
"custom_attributes"_a = CustomAttributes{})
.def_ro("name", &Node::name)
.def_rw("name", &Node::name)
.def("__getstate__", &helpers::node_to_tuple)
.def("__setstate__", &helpers::tuple_to_node)
.def("to_dict", &helpers::node_to_dict);
Expand Down Expand Up @@ -349,13 +349,17 @@ NB_MODULE(ext, m) {
"is_toplevel"_a,
"custom_attributes"_a = CustomAttributes{},
"targets_documents"_a = Link::TargetsDocuments{})
.def_prop_ro("composite_type",
[](const Link& self) -> const nb::list {
return helpers::composite_type_to_pylist(self.composite_type);
})
.def_ro("named_type_hash", &Link::named_type_hash)
.def_ro("targets", &Link::targets)
.def_ro("is_toplevel", &Link::is_toplevel)
.def_prop_rw(
"composite_type",
[](const Link& self) -> const nb::list {
return helpers::composite_type_to_pylist(self.composite_type);
},
[](Link& self, const nb::list& composite_type) {
self.composite_type = helpers::pylist_to_composite_type(composite_type);
})
.def_rw("named_type_hash", &Link::named_type_hash)
.def_rw("targets", &Link::targets)
.def_rw("is_toplevel", &Link::is_toplevel)
.def_rw("targets_documents", &Link::targets_documents)
.def("__getstate__", &helpers::link_to_tuple)
.def("__setstate__", &helpers::tuple_to_link)
Expand Down