8000 [3.13] gh-131936: Strengthen check in `_suggestions._generate_suggest… · python/cpython@d52371c · GitHub
[go: up one dir, main page]

Skip to content

Commit d52371c

Browse files
[3.13] gh-131936: Strengthen check in _suggestions._generate_suggestions (GH-131945) (#131949)
gh-131936: Strengthen check in `_suggestions._generate_suggestions` (GH-131945) (cherry picked from commit 511d344) Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent b41c8cc commit d52371c

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

Lib/test/test_traceback.py

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4615,7 +4615,31 @@ def test_levenshtein_distance_short_circuit(self):
46154615
@cpython_only
46164616
def test_suggestions_extension(self):
46174617
# Check that the C extension is available
4618-
import _suggestions # noqa: F401
4618+
import _suggestions
4619+
4620+
self.assertEqual(
4621+
_suggestions._generate_suggestions(
4622+
["hello", "world"],
4623+
"hell"
4624+
),
4625+
"hello"
4626+
)
4627+
self.assertEqual(
4628+
_suggestions._generate_suggestions(
4629+
["hovercraft"],
4630+
"eels"
4631+
),
4632+
None
4633+
)
4634+
4635+
# gh-131936: _generate_suggestions() doesn't accept list subclasses
4636+
class MyList(list):
4637+
pass
4638+
4639+
with self.assertRaises(TypeError):
4640+
_suggestions._generate_suggestions(MyList(), "")
4641+
4642+
46194643

46204644

46214645
class TestColorizedTraceback(unittest.TestCase):

Modules/_suggestions.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ _suggestions__generate_suggestions_impl(PyObject *module,
2121
/*[clinic end generated code: output=79be7b653ae5e7ca input=ba2a8dddc654e33a]*/
2222
{
2323
// Check if dir is a list
24-
if (!PyList_Check(candidates)) {
24+
if (!PyList_CheckExact(candidates)) {
2525
PyErr_SetString(PyExc_TypeError, "candidates must be a list");
2626
return NULL;
2727
}

0 commit comments

Comments
 (0)
0