Skip to content

Commit 30f54f6

Browse files
committed
Handle readline stopiteration
1 parent 04371d3 commit 30f54f6

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

Lib/test/test_tokenize.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ def check_tokenize(self, s, expected):
5151
[" ENCODING 'utf-8' (0, 0) (0, 0)"] +
5252
expected.rstrip().splitlines())
5353

54-
@unittest.expectedFailure # TODO: RUSTPYTHON
5554
def test_invalid_readline(self):
5655
def gen():
5756
yield "sdfosdg"

stdlib/src/tokenize.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ mod _tokenize {
55
use crate::{
66
common::lock::PyRwLock,
77
vm::{
8-
Py, PyPayload, PyResult, VirtualMachine,
8+
AsObject, Py, PyPayload, PyResult, VirtualMachine,
99
builtins::{PyBytes, PyStr, PyStrRef, PyTypeRef},
1010
convert::ToPyObject,
1111
function::ArgCallable,
@@ -38,7 +38,12 @@ mod _tokenize {
3838
// we need to check if it's callable and raise a type error if it's not.
3939
let raw_line = match self.readline.invoke((), vm) {
4040
Ok(v) => v,
41-
Err(_) => return Ok(String::new()),
41+
Err(err) => {
42+
if err.fast_isinstance(vm.ctx.exceptions.stop_iteration) {
43+
return Ok(String::new());
44+
}
45+
return Err(err);
46+
}
4247
};
4348
Ok(match &self.encoding {
4449
Some(encoding) => {

0 commit comments

Comments
 (0)