Skip to content
New issue

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

gh-129098: avoid using content of _pyrepl/__main__.py when reporting tracebacks #130721

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

picnixz
Copy link
Member

@picnixz picnixz commented Mar 1, 2025

I don't know how to test this :)

@picnixz picnixz changed the title gh- 129098: avoid using content of _pyrepl/__main__.py when reporting tracebacks gh-129098: avoid using content of _pyrepl/__main__.py when reporting tracebacks Mar 1, 2025
@picnixz
Copy link
Member Author

picnixz commented Mar 2, 2025

I'm marking the PR as ready for review to know whether this is the correct alternative.

@picnixz picnixz marked this pull request as ready for review March 2, 2025 00:13
@skirpichev
Copy link
Member

I don't know how to test this :)

Maybe something like this (that for unpatched version):

diff --git a/Lib/test/test_pyrepl/test_pyrepl.py b/Lib/test/test_pyrepl/test_pyrepl.py
index 3540d2a5a4..1d76121364 100644
--- a/Lib/test/test_pyrepl/test_pyrepl.py
+++ b/Lib/test/test_pyrepl/test_pyrepl.py
@@ -1216,6 +1216,15 @@ 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):
+        env = os.environ.copy()
+        commands = "eval(compile('spam', 'spam', 'eval'))\nexit()\n"
+        env.pop("PYTHON_BASIC_REPL", None)
+        output, exit_code = self.run_repl(commands, env=env)
+        self.assertIn("Traceback", output)
+        self.assertIn("# Important: don't add things to this module", output)
+
     @force_not_colorized
     def test_bad_sys_excepthook_doesnt_crash_pyrepl(self):
         env = os.environ.copy()

@picnixz picnixz added the needs backport to 3.13 bugs and security fixes label Mar 14, 2025
@picnixz
Copy link
Member Author

picnixz commented Mar 23, 2025

@pablogsal @ambv Could you have a look at this one to see if we can use this fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants