@@ -155,9 +155,35 @@ func (c *Attribute) Index(i int) starlark.Value {
155
155
return NewAttributeWithPath (c .r , * c .t .ListElementType (), c .name , path )
156
156
}
157
157
158
+ if c .t .IsMapType () {
159
+ return NewAttributeWithPath (c .r , c .t , c .name , path )
160
+ }
161
+
158
162
return starlark .None
159
163
}
160
164
165
+ // Get honors the starlark.Mapping interface.
166
+ func (c * Attribute ) Get (key starlark.Value ) (v starlark.Value , found bool , err error ) {
167
+ switch vKey := key .(type ) {
168
+ case starlark.Int :
169
+ if ! c .t .IsSetType () && ! c .t .IsListType () && ! c .t .IsMapType () {
170
+ return nil , false , fmt .Errorf ("%s does not support index" , c .name )
171
+ }
172
+
173
+ index , _ := vKey .Int64 ()
174
+ return c .Index (int (index )), true , nil
175
+ case starlark.String :
176
+ if ! c .t .IsMapType () {
177
+ return nil , false , fmt .Errorf ("%s it's not a dict" , c .name )
178
+ }
179
+
180
+ path := fmt .Sprintf ("%s.%s" , c .path , vKey .GoString ())
181
+ return NewAttributeWithPath (c .r , c .t , c .name , path ), true , nil
182
+ default :
183
+ return nil , false , fmt .Errorf ("%s: unexpected key type %s" , c .name , key .Type ())
184
+ }
185
+ }
186
+
161
187
// Len honors the starlark.Indexable interface.
162
188
func (c * Attribute ) Len () int {
163
189
if ! c .t .IsSetType () && ! c .t .IsListType () {
0 commit comments