Skip to content

Commit 1f2a89a

Browse files
authored
Refactor delattrbehavior calls (#225)
1 parent 32bedfe commit 1f2a89a

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

atom/src/delattrbehavior.cpp

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,7 @@ _mangled_property_handler( Member* member, CAtom* atom )
155155
cppy::ptr name( PyUnicode_FromFormat( "_del_%s", suffix ) );
156156
if( !name )
157157
return -1;
158-
cppy::ptr callable( PyObject_GetAttr( pyobject_cast( atom ), name.get() ) );
159-
if( !callable )
160-
{
161-
if( PyErr_ExceptionMatches( PyExc_AttributeError ) )
162-
PyErr_SetString( PyExc_AttributeError, "can't delete attribute" );
163-
return -1;
164-
}
165-
cppy::ptr args( PyTuple_New( 0 ) );
166-
if( !args )
167-
return -1;
168-
cppy::ptr ok( callable.call( args ) );
158+
cppy::ptr ok( PyObject_CallMethodNoArgs( pyobject_cast( atom ), name.get() ) );
169159
if( !ok )
170160
return -1;
171161
return 0;
@@ -177,11 +167,7 @@ property_handler( Member* member, CAtom* atom )
177167
{
178168
if( member->delattr_context != Py_None )
179169
{
180-
cppy::ptr args( PyTuple_New( 1 ) );
181-
if( !args )
182-
return -1;
183-
PyTuple_SET_ITEM( args.get(), 0, cppy::incref( pyobject_cast( atom ) ) );
184-
cppy::ptr ok( PyObject_Call( member->delattr_context, args.get(), 0 ) );
170+
cppy::ptr ok( PyObject_CallOneArg( member->delattr_context, pyobject_cast( atom ) ) );
185171
if( !ok )
186172
return -1;
187173
return 0;

0 commit comments

Comments
 (0)