@@ -100,34 +100,58 @@ func SetItem(self Object, key Object, value Object) Object {
100
100
}
101
101
102
102
// GetAttrOrNil - returns the result nil if attribute not found
103
- func GetAttrOrNil (self Object , key string ) Object {
103
+ func GetAttrOrNil (self Object , key string ) ( res Object ) {
104
104
// Call __getattribute unconditionally if it exists
105
105
if I , ok := self .(I__getattribute__ ); ok {
106
- return I .M__getattribute__ (Object (String (key )))
107
- } else if res , ok := TypeCall1 (self , "__getattribute__" , Object (String (key ))); ok {
106
+ res = I .M__getattribute__ (Object (String (key )))
107
+ goto found
108
+ } else if res , ok = TypeCall1 (self , "__getattribute__" , Object (String (key ))); ok {
108
109
// FIXME catch AttributeError here
109
- return res
110
+ goto found
110
111
}
111
112
112
113
if t , ok := self .(* Type ); ok {
113
114
// Now look in the instance dictionary etc
114
- res : = t .GetAttrOrNil (key )
115
+ res = t .GetAttrOrNil (key )
115
116
if res != nil {
116
- return res
117
+ goto found
117
118
}
118
119
} else {
119
120
// FIXME introspection for M__methods__ on non *Type objects
120
121
}
121
122
122
123
// And now only if not found call __getattr__
123
124
if I , ok := self .(I__getattr__ ); ok {
124
- return I .M__getattr__ (Object (String (key )))
125
- } else if res , ok := TypeCall1 (self , "__getitem__" , Object (String (key ))); ok {
126
- return res
125
+ res = I .M__getattr__ (Object (String (key )))
126
+ goto found
127
+ } else if res , ok = TypeCall1 (self , "__getattr__" , Object (String (key ))); ok {
128
+ goto found
127
129
}
128
130
129
131
// Not found - return nil
130
- return nil
132
+ res = nil
133
+ return
134
+
135
+ found:
136
+ // FIXME if self is an instance then if it returning a function then it needs to return a bound method?
137
+ // otherwise it should return a function
138
+ //
139
+ // >>> str.find
140
+ // <method 'find' of 'str' objects>
141
+ // >>> "".find
142
+ // <built-in method find of str object at 0x7f929bd54c00>
143
+ // >>>
144
+ //
145
+ // created by PyMethod_New defined in classobject.c
146
+ // called by type.tp_descr_get
147
+
148
+ // FIXME Not completely correct!
149
+ // Should be using __get__
150
+ switch res .(type ) {
151
+ case * Function , * Method :
152
+ res = NewBoundMethod (self , res )
153
+ }
154
+ return
131
155
}
132
156
133
157
// GetAttrString
0 commit comments