| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,6 @@ | ||
| # Important: don't add things to this module, as they will end up in the REPL's | ||
| # default globals. Use _pyrepl.main instead. | ||
|
|
||
| if __name__ == "__main__": | ||
| from .main import interactive_console as __pyrepl_interactive_console | ||
| __pyrepl_interactive_console() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Fix regression in the new REPL that meant that globals from files passed | ||
| using the ``-i`` argument would not be included in the REPL's global | ||
| namespace. Patch by Alex Waygood. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| Expand Up | @@ -4,6 +4,7 @@ | |
| #include "pycore_call.h" // _PyObject_CallNoArgs() | ||
| #include "pycore_initconfig.h" // _PyArgv | ||
| #include "pycore_interp.h" // _PyInterpreterState.sysdict | ||
| #include "pycore_long.h" // _PyLong_GetOne() | ||
| #include "pycore_pathconfig.h" // _PyPathConfig_ComputeSysPath0() | ||
| #include "pycore_pylifecycle.h" // _Py_PreInitializeFromPyArgv() | ||
| #include "pycore_pystate.h" // _PyInterpreterState_GET() | ||
| Expand Down Expand Up | @@ -259,6 +260,53 @@ pymain_run_command(wchar_t *command) | |
| } | ||
|
|
||
|
|
||
| static int | ||
| pymain_start_pyrepl_no_main(void) | ||
| { | ||
| int res = 0; | ||
| PyObject *pyrepl, *console, *empty_tuple, *kwargs, *console_result; | ||
| pyrepl = PyImport_ImportModule("_pyrepl.main"); | ||
| if (pyrepl == NULL) { | ||
| fprintf(stderr, "Could not import _pyrepl.main\n"); | ||
| res = pymain_exit_err_print(); | ||
| goto done; | ||
| } | ||
| console = PyObject_GetAttrString(pyrepl, "interactive_console"); | ||
| if (console == NULL) { | ||
| fprintf(stderr, "Could not access _pyrepl.main.interactive_console\n"); | ||
| res = pymain_exit_err_print(); | ||
| goto done; | ||
| } | ||
| empty_tuple = PyTuple_New(0); | ||
| if (empty_tuple == NULL) { | ||
| res = pymain_exit_err_print(); | ||
| goto done; | ||
| } | ||
| kwargs = PyDict_New(); | ||
| if (kwargs == NULL) { | ||
| res = pymain_exit_err_print(); | ||
| goto done; | ||
| } | ||
| if (!PyDict_SetItemString(kwargs, "pythonstartup", _PyLong_GetOne())) { | ||
| _PyRuntime.signals.unhandled_keyboard_interrupt = 0; | ||
| console_result = PyObject_Call(console, empty_tuple, kwargs); | ||
| if (!console_result && PyErr_Occurred() == PyExc_KeyboardInterrupt) { | ||
| _PyRuntime.signals.unhandled_keyboard_interrupt = 1; | ||
| } | ||
| if (console_result == NULL) { | ||
| res = pymain_exit_err_print(); | ||
| } | ||
| } | ||
| done: | ||
| Py_XDECREF(console_result); | ||
| Py_XDECREF(kwargs); | ||
| Py_XDECREF(empty_tuple); | ||
| Py_XDECREF(console); | ||
| Py_XDECREF(pyrepl); | ||
| return res; | ||
| } | ||
|
|
||
|
|
||
| static int | ||
| pymain_run_module(const wchar_t *modname, int set_argv0) | ||
| { | ||
| Expand Down Expand Up | @@ -549,7 +597,7 @@ pymain_repl(PyConfig *config, int *exitcode) | |
| *exitcode = (run != 0); | ||
| return; | ||
| } | ||
| int run = pymain_run_module(L"_pyrepl", 0); | ||
| int run = pymain_start_pyrepl_no_main(); | ||
|
Comment thread
Copy link
Copy Markdown
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityMy first intuition was to simply PyImport_ImportModule("_pyrepl.__main__") but then the entire shell session is a side-effect of an on-going import, which was ugly and caused some funny edge cases (a non-zero exit was technically an ImportError). So instead we do the full dance of running _pyrepl.main.interactive_console(). While doing that I'm smuggling PYTHONSTARTUP support because:
Sorry, something went wrong.
All reactions
|
||
| *exitcode = (run != 0); | ||
| return; | ||
| } | ||
| Expand Down | ||
| Back | FazBrowse Home | New Git URL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low QualityThis was helpful to me when debugging weird behavior so I decided to keep it.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.