Skip to content

Commit 89b1304

Browse files
authored
bpo-14916: use specified tokenizer fd for file input (GH-31006)
@pablogsal, sorry i failed to rebase to main, so i recreated #22190 (comment) > PyRun_InteractiveOne\*() functions allow to explicitily set fd instead of stdin. but stdin was hardcoded in readline call. > This patch does not fix target file for prompt unlike original bpo one : prompt fd is unrelated to tokenizer source which could be read only. It is more of a bugfix regarding the docs : actual documentation say "prompt the user" so one would expect prompt to go on stdout not a file for both PyRun_InteractiveOne\*() and PyRun_InteractiveLoop\*(). Automerge-Triggered-By: GH:pablogsal
1 parent a0e55a5 commit 89b1304

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed bug in the tokenizer that prevented ``PyRun_InteractiveOne`` from parsing from the provided FD.

Parser/tokenizer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ tok_underflow_interactive(struct tok_state *tok) {
855855
tok->done = E_INTERACT_STOP;
856856
return 1;
857857
}
858-
char *newtok = PyOS_Readline(stdin, stdout, tok->prompt);
858+
char *newtok = PyOS_Readline(tok->fp ? tok->fp : stdin, stdout, tok->prompt);
859859
if (newtok != NULL) {
860860
char *translated = translate_newlines(newtok, 0, tok);
861861
PyMem_Free(newtok);

0 commit comments

Comments
 (0)