Skip to content

Commit 1ecd328

Browse files
[Sofa.Core.Node]: Improve deprecation message when using getobject. (#199)
* [bindings/Core] Improve the deprecation message for Node::getObject() * [Sofa.Core] Improve the deprecation message for Node::getObject()
1 parent eef6747 commit 1ecd328

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

Plugin/src/SofaPython3/PythonFactory.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,16 @@ void PythonFactory::fromPython(BaseData* d, const py::object& o)
346346
// To smooth the deprecation process we are still allowing it ...but prints a warning.
347347
if( !nfo.Text() && py::isinstance<py::str>(o) )
348348
{
349-
msg_deprecated(d->getOwner()) << "Data field '" << d->getName() << "' is initialized from a string."
350-
<< " This behavior was allowed with SofaPython2 but have very poor performance so it is now "
351-
<< "deprecated with SofaPython3. Please fix your scene (as this behavior will be removed)."
352-
<< PythonEnvironment::getPythonCallingPointString();
353-
d->read( py::cast<std::string>(o) );
349+
std::string s = py::cast<std::string>(o);
350+
if(s.size() > 1 && s[0] != '@')
351+
{
352+
msg_deprecated(d->getOwner()) << "Data field '" << d->getName() << "' is initialized from a string." << msgendl
353+
<< " This behavior was allowed with SofaPython2 but have very poor performance so it is now "
354+
<< "deprecated with SofaPython3. Please fix your scene (as this behavior will be removed)." << msgendl
355+
<< msgendl
356+
<< PythonEnvironment::getPythonCallingPointString();
357+
}
358+
d->read( s );
354359
return;
355360
}
356361

bindings/Sofa/src/SofaPython3/Sofa/Core/Binding_Node.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ py::object getObject(Node &n, const std::string &name, const py::kwargs& kwargs)
172172
if(kwargs.size()!=0)
173173
{
174174
msg_deprecated(&n) << "Calling the method getObject() with extra arguments is not supported anymore."
175-
<< "To remove this message please refer to the documentation of the getObject method";
175+
<< "To remove this message please refer to the documentation of the getObject method"
176+
<< msgendl
177+
<< PythonEnvironment::getPythonCallingPointString() ;
176178
}
177179

178180
BaseObject *object = n.getObject(name);

0 commit comments

Comments
 (0)