Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-130999: Avoid exiting the new REPL when there are non-string candidates for suggestions #131001

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Avoid exiting the new REPL when there are non-string candidates for s…
…uggestions.
  • Loading branch information
devdanzin committed Mar 9, 2025
commit b3055abae2d56f37ac82edce709eea6c581f408a
13 changes: 8 additions & 5 deletions 13 Lib/_pyrepl/console.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,11 +169,14 @@ def showsyntaxerror(self, filename=None, **kwargs):

def _excepthook(self, typ, value, tb):
import traceback
lines = traceback.format_exception(
typ, value, tb,
colorize=self.can_colorize,
limit=traceback.BUILTIN_EXCEPTION_LIMIT)
self.write(''.join(lines))
try:
lines = traceback.format_exception(
typ, value, tb,
colorize=self.can_colorize,
limit=traceback.BUILTIN_EXCEPTION_LIMIT)
self.write(''.join(lines))
except TypeError as e:
self.write(repr(e) + '\n')

def runcode(self, code):
try:
Expand Down
9 changes: 9 additions & 0 deletions 9 Lib/test/test_pyrepl/test_pyrepl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,15 @@ def test_null_byte(self):
self.assertEqual(exit_code, 0)
self.assertNotIn("TypeError", output)

def test_non_string_suggestion_candidates(self):
commands = ("import runpy\n"
"runpy._run_module_code('blech', {0: '', 'bluch': ''}, '')\n"
"exit()\n")

output, exit_code = self.run_repl(commands)
self.assertEqual(exit_code, 0)
self.assertIn("all elements in 'candidates' must be strings", output)

def test_readline_history_file(self):
# skip, if readline module is not available
readline = import_module('readline')
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.