Skip to content

Commit

Permalink
Merge 5ea3306 into cb0fc06
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-conalgo committed Mar 6, 2015
2 parents cb0fc06 + 5ea3306 commit 54f02c2
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
13 changes: 13 additions & 0 deletions py/objrange.c
Expand Up @@ -166,6 +166,18 @@ STATIC mp_obj_t range_getiter(mp_obj_t o_in) {
return mp_obj_new_range_iterator(o->start, o->stop, o->step);
}


STATIC void range_load_attr(mp_obj_t o_in, qstr attr, mp_obj_t *dest) {
mp_obj_range_t *o = o_in;
if (attr == MP_QSTR_start) {
dest[0] = mp_obj_new_int(o->start);
} else if (attr == MP_QSTR_stop) {
dest[0] = mp_obj_new_int(o->stop);
} else if (attr == MP_QSTR_step) {
dest[0] = mp_obj_new_int(o->step);
}
}

const mp_obj_type_t mp_type_range = {
{ &mp_type_type },
.name = MP_QSTR_range,
Expand All @@ -174,4 +186,5 @@ const mp_obj_type_t mp_type_range = {
.unary_op = range_unary_op,
.subscr = range_subscr,
.getiter = range_getiter,
.load_attr = range_load_attr,
};
3 changes: 3 additions & 0 deletions py/qstrdefs.h
Expand Up @@ -245,6 +245,9 @@ Q(single)
Q(sep)
Q(end)

Q(step)
Q(stop)

Q(clear)
Q(copy)
Q(fromkeys)
Expand Down
5 changes: 5 additions & 0 deletions tests/basics/builtin_range.py
Expand Up @@ -24,3 +24,8 @@
print(range(4)[1:3])
print(range(4)[1::2])
print(range(4)[1:-2:2])

# attrs
print(range(1, 2, 3).start)
print(range(1, 2, 3).stop)
print(range(1, 2, 3).step)

0 comments on commit 54f02c2

Please sign in to comment.