mirror of
https://github.com/RustPython/RustPython.git
synced 2026-06-09 22:49:57 +09:00
Merge pull request #2966 from Snowapril/fix-range-iter
Disable `range_iterator` and `longrange_iterator` creation by calling its type
This commit is contained in:
@@ -502,8 +502,6 @@ class RangeTest(unittest.TestCase):
|
||||
test_id = "reversed(range({}, {}, {}))".format(start, end, step)
|
||||
self.assert_iterators_equal(iter1, iter2, test_id, limit=100)
|
||||
|
||||
# TODO: RUSTPYTHON
|
||||
@unittest.expectedFailure
|
||||
def test_range_iterators_invocation(self):
|
||||
# verify range iterators instances cannot be created by
|
||||
# calling their type
|
||||
|
||||
@@ -483,6 +483,11 @@ impl PyValue for PyLongRangeIterator {
|
||||
|
||||
#[pyimpl(with(PyIter))]
|
||||
impl PyLongRangeIterator {
|
||||
#[pyslot]
|
||||
fn tp_new(_cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
Err(vm.new_type_error("cannot create 'longrange_iterator' instances".to_owned()))
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> BigInt {
|
||||
let index = BigInt::from(self.index.load());
|
||||
@@ -546,6 +551,11 @@ impl PyValue for PyRangeIterator {
|
||||
|
||||
#[pyimpl(with(PyIter))]
|
||||
impl PyRangeIterator {
|
||||
#[pyslot]
|
||||
fn tp_new(_cls: PyTypeRef, _args: FuncArgs, vm: &VirtualMachine) -> PyResult {
|
||||
Err(vm.new_type_error("cannot create 'range_iterator' instances".to_owned()))
|
||||
}
|
||||
|
||||
#[pymethod(magic)]
|
||||
fn length_hint(&self) -> usize {
|
||||
let index = self.index.load();
|
||||
|
||||
Reference in New Issue
Block a user