Skip to content

Commit

Permalink
Merge pull request #2749 from ntoxeg/fix/python-queuevalue
Browse files Browse the repository at this point in the history
Fix QueueValue in Python API
  • Loading branch information
linas authored Aug 7, 2020
2 parents 09c8f1a + fbb8b51 commit e83d893
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
8 changes: 1 addition & 7 deletions opencog/cython/opencog/link_value.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,6 @@ cdef class LinkValue(Value):
cdef cValuePtr value
while it != cpp_vector.const_end():
value = deref(it)
if is_a(deref(value).get_type(), types.Value):
list.append(create_python_value_from_c_value(value))
else:
# TODO: Support Atoms as members of LinkValue requires inheriting
# Atom from Value and constructor to create Atom from cHandle.
raise TypeError('Only Values are supported '
'as members of LinkValue')
list.append(create_python_value_from_c_value(value))
inc(it)
return list
14 changes: 11 additions & 3 deletions opencog/cython/opencog/nameserver.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,23 @@ cdef create_python_value_from_c_value(const cValuePtr& value):
thismodule = sys.modules[__name__]
clazz = getattr(thismodule, type_name, None)
if clazz is not None:
return clazz(ptr_holder = ptr_holder)
return clazz(ptr_holder=ptr_holder)

# For handling the children types of TruthValue.
if is_a(value_type, types.TruthValue):
return TruthValue(ptr_holder = ptr_holder)
return TruthValue(ptr_holder=ptr_holder)

# For handling the children types of LinkValue.
if is_a(value_type, types.LinkValue):
return LinkValue(ptr_holder=ptr_holder)

# For handling the children types of Atom.
if is_a(value_type, types.Atom):
return Atom(ptr_holder = ptr_holder)
return Atom(ptr_holder=ptr_holder)

# For handling the children types of Value.
if is_a(value_type, types.Value):
return Value(ptr_holder=ptr_holder)

raise TypeError("Python API for " + type_name + " is not implemented yet")

Expand Down
2 changes: 1 addition & 1 deletion opencog/cython/opencog/utilities.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@ cdef extern from "opencog/cython/executioncontext/Context.h" namespace "opencog"
# but is installed to "opencog/persist/file/". Cython wants the
# source location, not the install location.
cdef extern from "opencog/persist/sexpr/fast_load.h" namespace "opencog":
void load_file(const string path, cAtomSpace & atomspace);
void c_load_file "opencog::load_file" (const string path, cAtomSpace & atomspace);
4 changes: 2 additions & 2 deletions opencog/cython/opencog/utilities.pyx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from cython.operator cimport dereference as deref
from libcpp.string cimport string
from opencog.atomspace cimport AtomSpace, Atom, TruthValue
from opencog.atomspace cimport AtomSpace, Atom, TruthValue, Value
from opencog.atomspace cimport cValuePtr, create_python_value_from_c_value
from opencog.atomspace cimport AtomSpace_factory

from contextlib import contextmanager
from opencog.atomspace import create_child_atomspace
from opencog.utilities cimport load_file as c_load_file
from opencog.utilities cimport c_load_file
import warnings


Expand Down

0 comments on commit e83d893

Please sign in to comment.