@@ -67,33 +67,24 @@ public static NewReference tp_getattro(BorrowedReference ob, BorrowedReference k
6767 {
6868 var result = Runtime . PyObject_GenericGetAttr ( ob , key ) ;
6969
70- // Property not found, but it can still be a dynamic one if the object is an IDynamicMetaObjectProvider
71- if ( result . IsNull ( ) )
70+ // If AttributeError was raised, we try to get the attribute from the managed object dynamic properties.
71+ if ( Exceptions . ExceptionMatches ( Exceptions . AttributeError ) )
7272 {
7373 var clrObj = ( CLRObject ) GetManagedObject ( ob ) ! ;
74- if ( clrObj ? . inst is IDynamicMetaObjectProvider )
75- {
76-
77- // The call to Runtime.PyObject_GenericGetAttr above ended up with an AttributeError
78- // for dynamic properties since they are not found in the C# object definition.
79- if ( Exceptions . ExceptionMatches ( Exceptions . AttributeError ) )
80- {
81- Exceptions . Clear ( ) ;
82- }
8374
84- var name = Runtime . GetManagedString ( key ) ;
85- var clrObjectType = clrObj . inst . GetType ( ) ;
86- var callSite = GetAttrCallSite ( name , clrObjectType ) ;
75+ var name = Runtime . GetManagedString ( key ) ;
76+ var clrObjectType = clrObj . inst . GetType ( ) ;
77+ var callSite = GetAttrCallSite ( name , clrObjectType ) ;
8778
88- try
89- {
90- var res = callSite . Target ( callSite , clrObj . inst ) ;
91- return Converter . ToPython ( res ) ;
92- }
93- catch ( RuntimeBinder . RuntimeBinderException )
94- {
95- Exceptions . SetError ( Exceptions . AttributeError , $ "' { clrObjectType } ' object has no attribute ' { name } '" ) ;
96- }
79+ try
80+ {
81+ var res = callSite . Target ( callSite , clrObj . inst ) ;
82+ Exceptions . Clear ( ) ;
83+ result = Converter . ToPython ( res ) ;
84+ }
85+ catch ( RuntimeBinder . RuntimeBinderException )
86+ {
87+ // Do nothing, AttributeError was already raised in Python side and it was not cleared.
9788 }
9889 }
9990
0 commit comments