Skip to content

[3.15] gh-152132: Fix Py_RunMain() to return an exit code (GH-153446)#153454

Merged
vstinner merged 1 commit into
python:3.15from
miss-islington:backport-fac72f1-3.15
Jul 9, 2026
Merged

[3.15] gh-152132: Fix Py_RunMain() to return an exit code (GH-153446)#153454
vstinner merged 1 commit into
python:3.15from
miss-islington:backport-fac72f1-3.15

Conversation

@miss-islington

@miss-islington miss-islington commented Jul 9, 2026

Copy link
Copy Markdown
Contributor
  • Fix Py_RunMain() to return an exit code, rather than calling
    Py_Exit(), when running a script, a command, or the REPL.

  • _PyRun_SimpleFile() now logs errors to stderr, for example if setting
    main.file fails.

  • Add tests on Py_RunMain() exitcode.

  • Rename functions:

    • _PyRun_SimpleStringFlagsWithName() => _PyRun_SimpleString()
    • _PyRun_SimpleFileObject() => _PyRun_SimpleFile()
    • _PyRun_AnyFileObject() => _PyRun_AnyFile()
    • _PyRun_InteractiveLoopObject() => _PyRun_InteractiveLoop()
  • Change _PyRun_SimpleString(), _PyRun_SimpleFile(), _PyRun_AnyFile() and
    _PyRun_InteractiveLoop() return type to PyObject*.

  • pymain_repl() now displays the error if PySys_Audit() or
    import _pyrepl failed.

  • PyRun_SimpleFileExFlags() and PyRun_AnyFileExFlags() now log
    PyUnicode_DecodeFSDefault() error. So these functions can no longer
    return -1 with an exception set.
    (cherry picked from commit fac72f1)

Co-authored-by: Victor Stinner vstinner@python.org

…3446)

* Fix Py_RunMain() to return an exit code, rather than calling
  Py_Exit(), when running a script, a command, or the REPL.
* _PyRun_SimpleFile() now logs errors to stderr, for example if setting
  __main__.__file__ fails.
* Add tests on Py_RunMain() exitcode.
* Rename functions:

  * _PyRun_SimpleStringFlagsWithName() => _PyRun_SimpleString()
  * _PyRun_SimpleFileObject() => _PyRun_SimpleFile()
  * _PyRun_AnyFileObject() => _PyRun_AnyFile()
  * _PyRun_InteractiveLoopObject() => _PyRun_InteractiveLoop()

* Change _PyRun_SimpleString(), _PyRun_SimpleFile(), _PyRun_AnyFile() and
  _PyRun_InteractiveLoop() return type to PyObject*.
* pymain_repl() now displays the error if PySys_Audit() or
  import _pyrepl failed.
* PyRun_SimpleFileExFlags() and PyRun_AnyFileExFlags() now log
  PyUnicode_DecodeFSDefault() error. So these functions can no longer
  return -1 with an exception set.
(cherry picked from commit fac72f1)

Co-authored-by: Victor Stinner <vstinner@python.org>
@vstinner vstinner enabled auto-merge (squash) July 9, 2026 18:36
@vstinner vstinner merged commit 76c28fc into python:3.15 Jul 9, 2026
55 checks passed
@miss-islington miss-islington deleted the backport-fac72f1-3.15 branch July 9, 2026 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants