@@ -214,22 +214,30 @@ public static int tp_setattro(IntPtr tp, IntPtr name, IntPtr value)
214214 if ( descr != IntPtr . Zero )
215215 {
216216 IntPtr dt = Runtime . PyObject_TYPE ( descr ) ;
217- IntPtr fp = Marshal . ReadIntPtr ( dt , TypeOffset . tp_descr_set ) ;
218- if ( fp != IntPtr . Zero )
217+
218+ if ( dt == Runtime . PyWrapperDescriptorType
219+ || dt == Runtime . PyMethodType
220+ || typeof ( ExtensionType ) . IsInstanceOfType ( GetManagedObject ( descr ) )
221+ )
219222 {
220- return NativeCall . Impl . Int_Call_3 ( fp , descr , name , value ) ;
223+ IntPtr fp = Marshal . ReadIntPtr ( dt , TypeOffset . tp_descr_set ) ;
224+ if ( fp != IntPtr . Zero )
225+ {
226+ return NativeCall . Impl . Int_Call_3 ( fp , descr , name , value ) ;
227+ }
228+ else
229+ {
230+ Exceptions . SetError ( Exceptions . AttributeError ,
231+ "attribute is read-only" ) ;
232+ return - 1 ;
233+ }
221234 }
222- Exceptions . SetError ( Exceptions . AttributeError ,
223- "attribute is read-only" ) ;
224- return - 1 ;
225235 }
226236
227- if ( Runtime . PyObject_GenericSetAttr ( tp , name , value ) < 0 )
228- {
229- return - 1 ;
230- }
237+ var res = Runtime . PyObject_GenericSetAttr ( tp , name , value ) ;
238+ Runtime . PyType_Modified ( tp ) ;
231239
232- return 0 ;
240+ return res ;
233241 }
234242
235243 //====================================================================
@@ -281,7 +289,8 @@ static IntPtr DoInstanceCheck(IntPtr tp, IntPtr args, bool checkType)
281289 {
282290 ClassBase cb = GetManagedObject ( tp ) as ClassBase ;
283291
284- if ( cb == null ) {
292+ if ( cb == null )
293+ {
285294 Runtime . XIncref ( Runtime . PyFalse ) ;
286295 return Runtime . PyFalse ;
287296 }
@@ -298,13 +307,15 @@ static IntPtr DoInstanceCheck(IntPtr tp, IntPtr args, bool checkType)
298307 else
299308 otherType = arg . GetPythonType ( ) ;
300309
301- if ( Runtime . PyObject_TYPE ( otherType . Handle ) != PyCLRMetaType ) {
310+ if ( Runtime . PyObject_TYPE ( otherType . Handle ) != PyCLRMetaType )
311+ {
302312 Runtime . XIncref ( Runtime . PyFalse ) ;
303313 return Runtime . PyFalse ;
304314 }
305315
306316 ClassBase otherCb = GetManagedObject ( otherType . Handle ) as ClassBase ;
307- if ( otherCb == null ) {
317+ if ( otherCb == null )
318+ {
308319 Runtime . XIncref ( Runtime . PyFalse ) ;
309320 return Runtime . PyFalse ;
310321 }
@@ -323,4 +334,4 @@ public static IntPtr __subclasscheck__(IntPtr tp, IntPtr args)
323334 return DoInstanceCheck ( tp , args , true ) ;
324335 }
325336 }
326- }
337+ }
0 commit comments