mirror of
https://github.com/python/cpython
synced 2026-09-29 12:10:30 +03:00
gh-110721: Remove unused code from suggestions.c after moving PyErr_Display to use the traceback module (#113712)
This commit is contained in:
parent
802d4954f1
commit
a03ec20bcd
12 changed files with 117 additions and 225 deletions
|
|
@ -11,6 +11,7 @@ faulthandler faulthandler.c
|
|||
posix posixmodule.c
|
||||
_signal signalmodule.c
|
||||
_tracemalloc _tracemalloc.c
|
||||
_suggestions _suggestions.c
|
||||
|
||||
# modules used by importlib, deepfreeze, freeze, runpy, and sysconfig
|
||||
_codecs _codecsmodule.c
|
||||
|
|
|
|||
63
Modules/_suggestions.c
Normal file
63
Modules/_suggestions.c
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
#include "Python.h"
|
||||
#include "pycore_pyerrors.h"
|
||||
#include "clinic/_suggestions.c.h"
|
||||
|
||||
/*[clinic input]
|
||||
module _suggestions
|
||||
[clinic start generated code]*/
|
||||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e58d81fafad5637b]*/
|
||||
|
||||
/*[clinic input]
|
||||
_suggestions._generate_suggestions
|
||||
candidates: object
|
||||
item: unicode
|
||||
/
|
||||
Returns the candidate in candidates that's closest to item
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
_suggestions__generate_suggestions_impl(PyObject *module,
|
||||
PyObject *candidates, PyObject *item)
|
||||
/*[clinic end generated code: output=79be7b653ae5e7ca input=ba2a8dddc654e33a]*/
|
||||
{
|
||||
// Check if dir is a list
|
||||
if (!PyList_Check(candidates)) {
|
||||
PyErr_SetString(PyExc_TypeError, "candidates must be a list");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// Check if all elements in the list are Unicode
|
||||
Py_ssize_t size = PyList_Size(candidates);
|
||||
for (Py_ssize_t i = 0; i < size; ++i) {
|
||||
PyObject *elem = PyList_GetItem(candidates, i);
|
||||
if (!PyUnicode_Check(elem)) {
|
||||
PyErr_SetString(PyExc_TypeError, "all elements in 'candidates' must be strings");
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
PyObject* result = _Py_CalculateSuggestions(candidates, item);
|
||||
if (!result && !PyErr_Occurred()) {
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef module_methods[] = {
|
||||
_SUGGESTIONS__GENERATE_SUGGESTIONS_METHODDEF
|
||||
{NULL, NULL, 0, NULL} // Sentinel
|
||||
};
|
||||
|
||||
static struct PyModuleDef suggestions_module = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"_suggestions",
|
||||
NULL,
|
||||
-1,
|
||||
module_methods
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC PyInit__suggestions(void) {
|
||||
return PyModule_Create(&suggestions_module);
|
||||
}
|
||||
|
||||
41
Modules/clinic/_suggestions.c.h
generated
Normal file
41
Modules/clinic/_suggestions.c.h
generated
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/*[clinic input]
|
||||
preserve
|
||||
[clinic start generated code]*/
|
||||
|
||||
#include "pycore_modsupport.h" // _PyArg_CheckPositional()
|
||||
|
||||
PyDoc_STRVAR(_suggestions__generate_suggestions__doc__,
|
||||
"_generate_suggestions($module, candidates, item, /)\n"
|
||||
"--\n"
|
||||
"\n"
|
||||
"Returns the candidate in candidates that\'s closest to item");
|
||||
|
||||
#define _SUGGESTIONS__GENERATE_SUGGESTIONS_METHODDEF \
|
||||
{"_generate_suggestions", _PyCFunction_CAST(_suggestions__generate_suggestions), METH_FASTCALL, _suggestions__generate_suggestions__doc__},
|
||||
|
||||
static PyObject *
|
||||
_suggestions__generate_suggestions_impl(PyObject *module,
|
||||
PyObject *candidates, PyObject *item);
|
||||
|
||||
static PyObject *
|
||||
_suggestions__generate_suggestions(PyObject *module, PyObject *const *args, Py_ssize_t nargs)
|
||||
{
|
||||
PyObject *return_value = NULL;
|
||||
PyObject *candidates;
|
||||
PyObject *item;
|
||||
|
||||
if (!_PyArg_CheckPositional("_generate_suggestions", nargs, 2, 2)) {
|
||||
goto exit;
|
||||
}
|
||||
candidates = args[0];
|
||||
if (!PyUnicode_Check(args[1])) {
|
||||
_PyArg_BadArgument("_generate_suggestions", "argument 2", "str", args[1]);
|
||||
goto exit;
|
||||
}
|
||||
item = args[1];
|
||||
return_value = _suggestions__generate_suggestions_impl(module, candidates, item);
|
||||
|
||||
exit:
|
||||
return return_value;
|
||||
}
|
||||
/*[clinic end generated code: output=1d8e963cdae30b13 input=a9049054013a1b77]*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue