Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 11 additions & 0 deletions Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -3166,6 +3166,17 @@ class A:
actual = self.get_suggestion(A(), 'bluch')
self.assertNotIn("blech", actual)

def test_suggestions_do_not_trigger_with_non_string_candidates(self):
class Parent:
def __dir__(self):
return [0]

class WithNonStringAttrs(Parent):
blech = None

result = self.get_suggestion(WithNonStringAttrs(), "bluch")
self.assertNotIn(result, "blech")

def test_getattr_suggestions_no_args(self):
class A:
blech = None
Expand Down
4 changes: 4 additions & 0 deletions Python/suggestions.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,10 @@ calculate_suggestions(PyObject *dir,
}
for (int i = 0; i < dir_size; ++i) {
PyObject *item = PyList_GET_ITEM(dir, i);
if (!PyUnicode_Check(item)) {
PyMem_Free(buffer);
return NULL;
}
if (_PyUnicode_Equal(name, item)) {
continue;
}
Expand Down
Loading