From c92b5b8399ec8609c589028aa8e302619c2a15c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?B=C3=A9n=C3=A9dikt=20Tran?= <10796600+picnixz@users.noreply.github.com> Date: Mon, 28 Apr 2025 11:48:06 +0200 Subject: [PATCH] Revert "gh-129098: avoid using content of `_pyrepl/__main__.py` when reporting tracebacks (#130721)" This reverts commit 492e3e6976d05b8de1892c37c900ada23eaeaf06. --- Lib/_pyrepl/__main__.py | 4 --- Lib/test/test_pyrepl/test_pyrepl.py | 29 ++----------------- ...-03-01-12-37-08.gh-issue-129098.eJ2-6L.rst | 2 -- 3 files changed, 2 insertions(+), 33 deletions(-) delete mode 100644 Misc/NEWS.d/next/Library/2025-03-01-12-37-08.gh-issue-129098.eJ2-6L.rst diff --git a/Lib/_pyrepl/__main__.py b/Lib/_pyrepl/__main__.py index 9c66812e13afa6..3fa992eee8eeff 100644 --- a/Lib/_pyrepl/__main__.py +++ b/Lib/_pyrepl/__main__.py @@ -1,10 +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. -# Avoid caching this file by linecache and incorrectly report tracebacks. -# See https://github.com/python/cpython/issues/129098. -__spec__ = __loader__ = None - if __name__ == "__main__": from .main import interactive_console as __pyrepl_interactive_console __pyrepl_interactive_console() diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py index c0d657e5db0eab..12ec349f2b4203 100644 --- a/Lib/test/test_pyrepl/test_pyrepl.py +++ b/Lib/test/test_pyrepl/test_pyrepl.py @@ -11,9 +11,9 @@ from unittest import TestCase, skipUnless, skipIf from unittest.mock import patch from test.support import force_not_colorized, make_clean_env -from test.support import SHORT_TIMEOUT, STDLIB_DIR +from test.support import SHORT_TIMEOUT from test.support.import_helper import import_module -from test.support.os_helper import EnvironmentVarGuard, unlink +from test.support.os_helper import unlink from .support import ( FakeConsole, @@ -1416,31 +1416,6 @@ def test_python_basic_repl(self): self.assertNotIn("Exception", output) self.assertNotIn("Traceback", output) - @force_not_colorized - def test_no_pyrepl_source_in_exc(self): - # Avoid using _pyrepl/__main__.py in traceback reports - # See https://github.com/python/cpython/issues/129098. - pyrepl_main_file = os.path.join(STDLIB_DIR, "_pyrepl", "__main__.py") - self.assertTrue(os.path.exists(pyrepl_main_file), pyrepl_main_file) - with open(pyrepl_main_file) as fp: - excluded_lines = fp.readlines() - excluded_lines = list(filter(None, map(str.strip, excluded_lines))) - - for filename in ['?', 'unknown-filename', '', '<...>']: - self._test_no_pyrepl_source_in_exc(filename, excluded_lines) - - def _test_no_pyrepl_source_in_exc(self, filename, excluded_lines): - with EnvironmentVarGuard() as env, self.subTest(filename=filename): - env.unset("PYTHON_BASIC_REPL") - commands = (f"eval(compile('spam', {filename!r}, 'eval'))\n" - f"exit()\n") - output, _ = self.run_repl(commands, env=env) - self.assertIn("Traceback (most recent call last)", output) - self.assertIn("NameError: name 'spam' is not defined", output) - for line in excluded_lines: - with self.subTest(line=line): - self.assertNotIn(line, output) - @force_not_colorized def test_bad_sys_excepthook_doesnt_crash_pyrepl(self): env = os.environ.copy() diff --git a/Misc/NEWS.d/next/Library/2025-03-01-12-37-08.gh-issue-129098.eJ2-6L.rst b/Misc/NEWS.d/next/Library/2025-03-01-12-37-08.gh-issue-129098.eJ2-6L.rst deleted file mode 100644 index 8ac9082a7b4d94..00000000000000 --- a/Misc/NEWS.d/next/Library/2025-03-01-12-37-08.gh-issue-129098.eJ2-6L.rst +++ /dev/null @@ -1,2 +0,0 @@ -Fix REPL traceback reporting when using :func:`compile` with an inexisting -file. Patch by Bénédikt Tran. pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy