summaryrefslogtreecommitdiffstats
path: root/Modules/main.c
diff options
context:
space:
mode:
authorPablo Galindo Salgado <Pablogsal@gmail.com>2024-05-05 19:32:23 (GMT)
committerGitHub <noreply@github.com>2024-05-05 19:32:23 (GMT)
commitf27f8c790af1233d499b795af1c0d1b36aaecaf5 (patch)
tree22c502c6382512fafbb63e3020c8462e5400d4df /Modules/main.c
parent40cc809902304f60c6e1c933191dd4d64e570e28 (diff)
downloadcpython-f27f8c790af1233d499b795af1c0d1b36aaecaf5.zip
cpython-f27f8c790af1233d499b795af1c0d1b36aaecaf5.tar.gz
cpython-f27f8c790af1233d499b795af1c0d1b36aaecaf5.tar.bz2
gh-111201: A new Python REPL (GH-111567)
Co-authored-by: Łukasz Langa <lukasz@langa.pl> Co-authored-by: Marta Gómez Macías <mgmacias@google.com> Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com> Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Modules/main.c')
-rw-r--r--Modules/main.c21
1 files changed, 16 insertions, 5 deletions
diff --git a/Modules/main.c b/Modules/main.c
index df2ce55..8eded26 100644
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -513,8 +513,13 @@ pymain_run_stdin(PyConfig *config)
return pymain_exit_err_print();
}
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
- int run = PyRun_AnyFileExFlags(stdin, "<stdin>", 0, &cf);
+ if (!isatty(fileno(stdin))
+ || _Py_GetEnv(config->use_environment, "PYTHON_BASIC_REPL")) {
+ PyCompilerFlags cf = _PyCompilerFlags_INIT;
+ int run = PyRun_AnyFileExFlags(stdin, "<stdin>", 0, &cf);
+ return (run != 0);
+ }
+ int run = pymain_run_module(L"_pyrepl", 0);
return (run != 0);
}
@@ -537,9 +542,15 @@ pymain_repl(PyConfig *config, int *exitcode)
return;
}
- PyCompilerFlags cf = _PyCompilerFlags_INIT;
- int res = PyRun_AnyFileFlags(stdin, "<stdin>", &cf);
- *exitcode = (res != 0);
+ if (!isatty(fileno(stdin))) {
+ PyCompilerFlags cf = _PyCompilerFlags_INIT;
+ int run = PyRun_AnyFileExFlags(stdin, "<stdin>", 0, &cf);
+ *exitcode = (run != 0);
+ return;
+ }
+ int run = pymain_run_module(L"_pyrepl", 0);
+ *exitcode = (run != 0);
+ return;
}