Skip to content

Commit 97d8529

Browse files
committed
Fix range attributes type
1 parent d29f5d7 commit 97d8529

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

Lib/test/test_range.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,9 +661,6 @@ def test_comparison(self):
661661
with self.assertRaises(TypeError):
662662
range(0) >= range(0)
663663

664-
665-
# TODO: RUSTPYTHON
666-
@unittest.expectedFailure
667664
def test_attributes(self):
668665
# test the start, stop and step attributes of range objects
669666
self.assert_attrs(range(0), 0, 0, 1)

vm/src/builtins/range.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,27 +181,32 @@ pub fn init(context: &Context) {
181181

182182
#[pyimpl(with(AsMapping, AsSequence, Hashable, Comparable, Iterable))]
183183
impl PyRange {
184-
fn new(cls: PyTypeRef, stop: PyIntRef, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
184+
fn new(cls: PyTypeRef, stop: PyObjectRef, vm: &VirtualMachine) -> PyResult<PyRef<Self>> {
185185
PyRange {
186186
start: vm.new_pyref(0),
187-
stop,
187+
stop: stop.try_index(vm)?,
188188
step: vm.new_pyref(1),
189189
}
190190
.into_ref_with_type(vm, cls)
191191
}
192192

193193
fn new_from(
194194
cls: PyTypeRef,
195-
start: PyIntRef,
196-
stop: PyIntRef,
197-
step: OptionalArg<PyIntRef>,
195+
start: PyObjectRef,
196+
stop: PyObjectRef,
197+
step: OptionalArg<PyObjectRef>,
198198
vm: &VirtualMachine,
199199
) -> PyResult<PyRef<Self>> {
200-
let step = step.unwrap_or_else(|| vm.new_pyref(1));
200+
let step = step.unwrap_or_else(|| vm.new_pyobj(1)).try_index(vm)?;
201201
if step.as_bigint().is_zero() {
202202
return Err(vm.new_value_error("range() arg 3 must not be zero".to_owned()));
203203
}
204-
PyRange { start, stop, step }.into_ref_with_type(vm, cls)
204+
PyRange {
205+
start: start.try_index(vm)?,
206+
stop: stop.try_index(vm)?,
207+
step,
208+
}
209+
.into_ref_with_type(vm, cls)
205210
}
206211

207212
#[pyproperty]

0 commit comments

Comments
 (0)