[Python-checkins] bpo-14916: use specified tokenizer fd for file input (GH-31006)

miss-islington webhook-mailer at python.org
Tue Feb 1 17:34:02 EST 2022


https://github.com/python/cpython/commit/89b13042fcfc95bae21a49806a205ef62f1cdd73
commit: 89b13042fcfc95bae21a49806a205ef62f1cdd73
branch: main
author: Paul m. p. P <mail.peny at free.fr>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
date: 2022-02-01T14:33:52-08:00
summary:

bpo-14916: use specified tokenizer fd for file input (GH-31006)



@pablogsal, sorry i failed to rebase to main, so i recreated https://github.com/python/cpython/pull/22190#issuecomment-1024633392

> 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

files:
A Misc/NEWS.d/next/C API/2020-09-11-02-50-41.bpo-14916.QN1Y03.rst
M Parser/tokenizer.c

diff --git a/Misc/NEWS.d/next/C API/2020-09-11-02-50-41.bpo-14916.QN1Y03.rst b/Misc/NEWS.d/next/C API/2020-09-11-02-50-41.bpo-14916.QN1Y03.rst
new file mode 100644
index 0000000000000..885cfc53aba38
--- /dev/null
+++ b/Misc/NEWS.d/next/C API/2020-09-11-02-50-41.bpo-14916.QN1Y03.rst	
@@ -0,0 +1 @@
+Fixed bug in the tokenizer that prevented ``PyRun_InteractiveOne`` from parsing from the provided FD.
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index cd4254f8b9077..5b5cbdb809ebe 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -855,7 +855,7 @@ tok_underflow_interactive(struct tok_state *tok) {
         tok->done = E_INTERACT_STOP;
         return 1;
     }
-    char *newtok = PyOS_Readline(stdin, stdout, tok->prompt);
+    char *newtok = PyOS_Readline(tok->fp ? tok->fp : stdin, stdout, tok->prompt);
     if (newtok != NULL) {
         char *translated = translate_newlines(newtok, 0, tok);
         PyMem_Free(newtok);



More information about the Python-checkins mailing list