mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
gh-130999: Avoid exiting the new REPL when there are non-string candidates for suggestions (gh-131001)
This commit is contained in:
parent
5f61cde80a
commit
baccfdb3d4
4 changed files with 48 additions and 2 deletions
|
@ -1595,7 +1595,11 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
|
|||
if isinstance(exc_value, AttributeError):
|
||||
obj = exc_value.obj
|
||||
try:
|
||||
d = dir(obj)
|
||||
try:
|
||||
d = dir(obj)
|
||||
except TypeError: # Attributes are unsortable, e.g. int and str
|
||||
d = list(obj.__class__.__dict__.keys()) + list(obj.__dict__.keys())
|
||||
d = sorted([x for x in d if isinstance(x, str)])
|
||||
hide_underscored = (wrong_name[:1] != '_')
|
||||
if hide_underscored and tb is not None:
|
||||
while tb.tb_next is not None:
|
||||
|
@ -1610,7 +1614,11 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
|
|||
elif isinstance(exc_value, ImportError):
|
||||
try:
|
||||
mod = __import__(exc_value.name)
|
||||
d = dir(mod)
|
||||
try:
|
||||
d = dir(mod)
|
||||
except TypeError: # Attributes are unsortable, e.g. int and str
|
||||
d = list(mod.__dict__.keys())
|
||||
d = sorted([x for x in d if isinstance(x, str)])
|
||||
if wrong_name[:1] != '_':
|
||||
d = [x for x in d if x[:1] != '_']
|
||||
except Exception:
|
||||
|
@ -1628,6 +1636,7 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
|
|||
+ list(frame.f_globals)
|
||||
+ list(frame.f_builtins)
|
||||
)
|
||||
d = [x for x in d if isinstance(x, str)]
|
||||
|
||||
# Check first if we are in a method and the instance
|
||||
# has the wrong name as attribute
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue