https://github.com/python/cpython/commit/d52371c8cdafeb61df92e9cea6b02e3c4d052765 commit: d52371c8cdafeb61df92e9cea6b02e3c4d052765 branch: 3.13 author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com> committer: vstinner <vstin...@python.org> date: 2025-03-31T17:54:20Z summary:
[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 511d3440a0bbb19731f4d96dde65dffbf85cdda5) Co-authored-by: Peter Bierma <zintensity...@gmail.com> files: M Lib/test/test_traceback.py M Modules/_suggestions.c diff --git a/Lib/test/test_traceback.py b/Lib/test/test_traceback.py index adc413d47d662c..2dfee81681d42d 100644 --- a/Lib/test/test_traceback.py +++ b/Lib/test/test_traceback.py @@ -4615,7 +4615,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() doesn't accept list subclasses + class MyList(list): + pass + + with self.assertRaises(TypeError): + _suggestions._generate_suggestions(MyList(), "") + + class TestColorizedTraceback(unittest.TestCase): diff --git a/Modules/_suggestions.c b/Modules/_suggestions.c index 80c7179c4c251c..b8bc6db2477281 100644 --- a/Modules/_suggestions.c +++ b/Modules/_suggestions.c @@ -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; } _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com