You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wouldn't be surprised if this behaviour is the result of expression templates at work.
Try using a temporary variable to prevent lazy evaluation of the expression on the right-hand side.
Also, to confirm: what is the result of calling the function you got ? That is, what is the output of py::exec("print(type(mol()))", globals); ?
Thanks for answer.
I can fix this by using simple if-else or casting dict and list to py::object explicitly.
But I wonder if this is expected behavior or bug
py::exec("print(type(mol()))", globals); ?
Probably <class 'list'> because I saw in debugger that &object::ptr would be written to globals["mol"].
Although I can't test right now
PS:
py::exec("print(type(mol()))", globals); ?
output:
PythonException:
Type: ArgumentError
Value: Python argument types in
None.None()
did not match C++ signature:
None(class boost::python::api::object {lvalue})
Traceback:
<string> : 1
Activity
stefanseefeld commentedon Jun 20, 2025
I wouldn't be surprised if this behaviour is the result of expression templates at work.
Try using a temporary variable to prevent lazy evaluation of the expression on the right-hand side.
Also, to confirm: what is the result of calling the function you got ? That is, what is the output of
py::exec("print(type(mol()))", globals);?sadseeker commentedon Jun 20, 2025
Thanks for answer.
I can fix this by using simple if-else or casting
dictandlisttopy::objectexplicitly.But I wonder if this is expected behavior or bug
Probably
<class 'list'>because I saw in debugger that&object::ptrwould be written toglobals["mol"].Although I can't test right now
PS:
output:
e-kwsm commentedon Oct 24, 2025
globals["mol"] = condition ? dict : list;Here
dictandlistmust have the same type.Try the folowing code
which prints
See https://stackoverflow.com/a/8535301.