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:
Jeong YunWon
2021-08-26 18:31:47 +09:00
committed by GitHub
2 changed files with 10 additions and 2 deletions

View File

@@ -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

View File

@@ -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();