@@ -12,8 +12,8 @@ public interface IGetAttr {
12
12
13
13
static class SlotOverrides {
14
14
public static IntPtr tp_getattro ( IntPtr ob , IntPtr key ) {
15
- IntPtr genericResult = Runtime . PyObject_GenericGetAttr ( ob , key ) ;
16
- if ( genericResult != IntPtr . Zero || ! Runtime . PyString_Check ( key ) ) {
15
+ if ( ! Runtime . PyString_Check ( key ) ) {
16
+ IntPtr genericResult = Runtime . PyObject_GenericGetAttr ( ob , key ) ;
17
17
return genericResult ;
18
18
}
19
19
@@ -43,7 +43,7 @@ public static bool TryGetBaseAttr(PyObject self, string name, out PyObject resul
43
43
if ( name == null ) throw new ArgumentNullException ( nameof ( name ) ) ;
44
44
45
45
using ( var super = new PyObject ( Runtime . PySuper ) )
46
- using ( var @class = self . GetAttr ( "__class__" ) )
46
+ using ( var @class = self . GetPythonType ( ) )
47
47
using ( var @base = super . Invoke ( @class , self ) ) {
48
48
if ( ! @base . HasAttr ( getAttr ) ) {
49
49
result = null ;
@@ -56,5 +56,25 @@ public static bool TryGetBaseAttr(PyObject self, string name, out PyObject resul
56
56
}
57
57
}
58
58
}
59
+
60
+ public static bool GenericGetAttr ( PyObject self , string name , out PyObject result ) {
61
+ if ( self == null ) throw new ArgumentNullException ( nameof ( self ) ) ;
62
+ if ( name == null ) throw new ArgumentNullException ( nameof ( name ) ) ;
63
+
64
+ using ( var pyName = name . ToPython ( ) ) {
65
+ IntPtr pyResult = Runtime . PyObject_GenericGetAttr ( self . Handle , pyName . Handle ) ;
66
+ if ( pyResult == IntPtr . Zero ) {
67
+ result = null ;
68
+ if ( ! PythonException . Matches ( Exceptions . AttributeError ) ) {
69
+ throw PythonException . FromPyErr ( ) ;
70
+ }
71
+
72
+ Exceptions . Clear ( ) ;
73
+ return false ;
74
+ }
75
+ result = new PyObject ( Runtime . SelfIncRef ( pyResult ) ) ;
76
+ return true ;
77
+ }
78
+ }
59
79
}
60
80
}
0 commit comments