GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-129900: Fix `SystemExit` return codes when the REPL is started fro… · python/cpython@90b82f2

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Lib/test
    • test_sys.py
  • Misc/NEWS.d/next/Core_and_Builtins
    • 2025-02-09-09-54-37.gh-issue-129900.GAGGPn.rst
  • Modules
    • main.c
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Lib/test/test_sys.py‎

Copy file name to clipboardExpand all lines: Lib/test/test_sys.py
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,27 @@ def check_exit_message(code, expected, **env_vars):
285285
r'import sys; sys.exit("h\xe9")',
286286
b"h\xe9", PYTHONIOENCODING='latin-1')
287287

288+
@support.requires_subprocess()
289+
def test_exit_codes_under_repl(self):
290+
# GH-129900: SystemExit, or things that raised it, didn't
291+
# get their return code propagated by the REPL
292+
import tempfile
293+
294+
exit_ways = [
295+
"exit",
296+
"__import__('sys').exit",
297+
"raise SystemExit"
298+
]
299+
300+
for exitfunc in exit_ways:
301+
for return_code in (0, 123):
302+
with self.subTest(exitfunc=exitfunc, return_code=return_code):
303+
with tempfile.TemporaryFile("w+") as stdin:
304+
stdin.write(f"{exitfunc}({return_code})\n")
305+
stdin.seek(0)
306+
proc = subprocess.run([sys.executable], stdin=stdin)
307+
self.assertEqual(proc.returncode, return_code)
308+
288309
def test_getdefaultencoding(self):
289310
self.assertRaises(TypeError, sys.getdefaultencoding, 42)
290311
# can't check more than the type, as the user might have changed it
Collapse file

‎Misc/NEWS.d/next/Core_and_Builtins/2025-02-09-09-54-37.gh-issue-129900.GAGGPn.rst‎

Copy file name to clipboard
+1Lines changed: 1 addition & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix return codes inside :exc:`SystemExit` not getting returned by the REPL.
Collapse file

‎Modules/main.c‎

Copy file name to clipboardExpand all lines: Modules/main.c
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,8 +556,7 @@ pymain_run_stdin(PyConfig *config)
556556
int run = PyRun_AnyFileExFlags(stdin, "<stdin>", 0, &cf);
557557
return (run != 0);
558558
}
559-
int run = pymain_run_module(L"_pyrepl", 0);
560-
return (run != 0);
559+
return pymain_run_module(L"_pyrepl", 0);
561560
}
562561

563562

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.