workaround in PyCXX classes due to removed support of old-style classes
This commit is contained in:
@@ -131,14 +131,23 @@ Py::Object Vector2dPy::repr()
|
||||
|
||||
Py::Object Vector2dPy::getattro(const Py::String &name_)
|
||||
{
|
||||
// For Py3 either handle __dict__ or implement __dir__ as shown here:
|
||||
// https://stackoverflow.com/questions/48609111/how-is-dir-implemented-exactly-and-how-should-i-know-it
|
||||
//
|
||||
std::string name( name_.as_std_string( "utf-8" ) );
|
||||
|
||||
if (name == "__members__") {
|
||||
if (name == "__members__") { // Py2
|
||||
Py::List attr;
|
||||
attr.append(Py::String("x"));
|
||||
attr.append(Py::String("y"));
|
||||
return attr;
|
||||
}
|
||||
else if (name == "__dict__") { // Py3
|
||||
Py::Dict attr;
|
||||
attr.setItem(Py::String("x"), Py::Float(v.x));
|
||||
attr.setItem(Py::String("y"), Py::Float(v.y));
|
||||
return attr;
|
||||
}
|
||||
else if (name == "x") {
|
||||
return Py::Float(v.x);
|
||||
}
|
||||
|
||||
@@ -157,6 +157,18 @@ namespace Py
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i = mm.find( name );
|
||||
if( i == mm.end() )
|
||||
{
|
||||
if( name == "__dict__" ) // __methods__ is not supported in Py3 any more, use __dict__ instead
|
||||
{
|
||||
Dict methods;
|
||||
|
||||
i = mm.begin();
|
||||
EXPLICIT_TYPENAME method_map_t::const_iterator i_end = mm.end();
|
||||
|
||||
for( ; i != i_end; ++i )
|
||||
methods.setItem( String( (*i).first ), String( "" ) );
|
||||
|
||||
return methods;
|
||||
}
|
||||
if( name == "__methods__" )
|
||||
{
|
||||
List methods;
|
||||
|
||||
Reference in New Issue
Block a user