mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
[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 511d3440a0)
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
This commit is contained in:
parent
b41c8cc671
commit
d52371c8cd
2 changed files with 26 additions and 2 deletions
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue