@@ -103,7 +103,7 @@ func SetItem(self Object, key Object, value Object) Object {
103
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
- res = I .M__getattribute__ (Object ( String ( key )) )
106
+ res = I .M__getattribute__ (key )
107
107
goto found
108
108
} else if res , ok = TypeCall1 (self , "__getattribute__" , Object (String (key ))); ok {
109
109
// FIXME catch AttributeError here
@@ -122,7 +122,7 @@ func GetAttrOrNil(self Object, key string) (res Object) {
122
122
123
123
// And now only if not found call __getattr__
124
124
if I , ok := self .(I__getattr__ ); ok {
125
- res = I .M__getattr__ (Object ( String ( key )) )
125
+ res = I .M__getattr__ (key )
126
126
goto found
127
127
} else if res , ok = TypeCall1 (self , "__getattr__" , Object (String (key ))); ok {
128
128
goto found
@@ -172,3 +172,33 @@ func GetAttr(self Object, keyObj Object) Object {
172
172
// FIXME should be TypeError
173
173
panic (fmt .Sprintf ("TypeError: attribute name must be string, not '%s'" , self .Type ().Name ))
174
174
}
175
+
176
+ // SetAttrString
177
+ func SetAttrString (self Object , key string , value Object ) Object {
178
+ if I , ok := self .(I__setattr__ ); ok {
179
+ return I .M__setattr__ (key , value )
180
+ } else if res , ok := TypeCall2 (self , "__setattr__" , String (key ), value ); ok {
181
+ return res
182
+ }
183
+
184
+ // Set the attribute on *Type
185
+ if t , ok := self .(* Type ); ok {
186
+ if t .Dict == nil {
187
+ t .Dict = make (StringDict )
188
+ }
189
+ t .Dict [key ] = value
190
+ return None
191
+ }
192
+
193
+ // FIXME should be TypeError
194
+ panic (fmt .Sprintf ("TypeError: '%s' object does not support setting attributes" , self .Type ().Name ))
195
+ }
196
+
197
+ // SetAttr
198
+ func SetAttr (self Object , keyObj Object , value Object ) Object {
199
+ if key , ok := keyObj .(String ); ok {
200
+ return GetAttrString (self , string (key ))
201
+ }
202
+ // FIXME should be TypeError
203
+ panic (fmt .Sprintf ("TypeError: attribute name must be string, not '%s'" , self .Type ().Name ))
204
+ }
0 commit comments