Skip to content

Commit c92b5b8

Browse files
committed
Revert "pythongh-129098: avoid using content of _pyrepl/__main__.py when reporting tracebacks (python#130721)"
This reverts commit 492e3e6.
1 parent 6677c2c commit c92b5b8

File tree

3 files changed

+2
-33
lines changed

3 files changed

+2
-33
lines changed

Lib/_pyrepl/__main__.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# Important: don't add things to this module, as they will end up in the REPL's
22
# default globals. Use _pyrepl.main instead.
33

4-
# Avoid caching this file by linecache and incorrectly report tracebacks.
5-
# See https://github.com/python/cpython/issues/129098.
6-
__spec__ = __loader__ = None
7-
84
if __name__ == "__main__":
95
from .main import interactive_console as __pyrepl_interactive_console
106
__pyrepl_interactive_console()

Lib/test/test_pyrepl/test_pyrepl.py

Lines changed: 2 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
from unittest import TestCase, skipUnless, skipIf
1212
from unittest.mock import patch
1313
from test.support import force_not_colorized, make_clean_env
14-
from test.support import SHORT_TIMEOUT, STDLIB_DIR
14+
from test.support import SHORT_TIMEOUT
1515
from test.support.import_helper import import_module
16-
from test.support.os_helper import EnvironmentVarGuard, unlink
16+
from test.support.os_helper import unlink
1717

1818
from .support import (
1919
FakeConsole,
@@ -1416,31 +1416,6 @@ def test_python_basic_repl(self):
14161416
self.assertNotIn("Exception", output)
14171417
self.assertNotIn("Traceback", output)
14181418

1419-
@force_not_colorized
1420-
def test_no_pyrepl_source_in_exc(self):
1421-
# Avoid using _pyrepl/__main__.py in traceback reports
1422-
# See https://github.com/python/cpython/issues/129098.
1423-
pyrepl_main_file = os.path.join(STDLIB_DIR, "_pyrepl", "__main__.py")
1424-
self.assertTrue(os.path.exists(pyrepl_main_file), pyrepl_main_file)
1425-
with open(pyrepl_main_file) as fp:
1426-
excluded_lines = fp.readlines()
1427-
excluded_lines = list(filter(None, map(str.strip, excluded_lines)))
1428-
1429-
for filename in ['?', 'unknown-filename', '<foo>', '<...>']:
1430-
self._test_no_pyrepl_source_in_exc(filename, excluded_lines)
1431-
1432-
def _test_no_pyrepl_source_in_exc(self, filename, excluded_lines):
1433-
with EnvironmentVarGuard() as env, self.subTest(filename=filename):
1434-
env.unset("PYTHON_BASIC_REPL")
1435-
commands = (f"eval(compile('spam', {filename!r}, 'eval'))\n"
1436-
f"exit()\n")
1437-
output, _ = self.run_repl(commands, env=env)
1438-
self.assertIn("Traceback (most recent call last)", output)
1439-
self.assertIn("NameError: name 'spam' is not defined", output)
1440-
for line in excluded_lines:
1441-
with self.subTest(line=line):
1442-
self.assertNotIn(line, output)
1443-
14441419
@force_not_colorized
14451420
def test_bad_sys_excepthook_doesnt_crash_pyrepl(self):
14461421
env = os.environ.copy()

Misc/NEWS.d/next/Library/2025-03-01-12-37-08.gh-issue-129098.eJ2-6L.rst

Lines changed: 0 additions & 2 deletions
This file was deleted.

0 commit comments

Comments
 (0)