Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
26 changes: 25 additions & 1 deletion Lib/test/test_traceback.py
Original file line number Diff line number Diff line change
Expand Up @@ -4619,7 +4619,31 @@ def test_levenshtein_distance_short_circuit(self):
@cpython_only
def test_suggestions_extension(self):
# Check that the C extension is available
import _suggestions # noqa: F401
import _suggestions

self.assertEqual(
_suggestions._generate_suggestions(
["hello", "world"],
"hell"
),
"hello"
)
self.assertEqual(
_suggestions._generate_suggestions(
["hovercraft"],
"eels"
),
None
)

# gh-131936: _generate_suggestions didn't check for exactly a list
class MyList(list):
pass

with self.assertRaises(TypeError):
_suggestions._generate_suggestions(MyList(), "")




class TestColorizedTraceback(unittest.TestCase):
Expand Down
2 changes: 1 addition & 1 deletion Modules/_suggestions.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _suggestions__generate_suggestions_impl(PyObject *module,
/*[clinic end generated code: output=79be7b653ae5e7ca input=ba2a8dddc654e33a]*/
{
// Check if dir is a list
if (!PyList_Check(candidates)) {
if (!PyList_CheckExact(candidates)) {
PyErr_SetString(PyExc_TypeError, "candidates must be a list");
return NULL;
}
Expand Down
Loading