mirror of
https://github.com/python/cpython.git
synced 2025-11-24 12:20:42 +00:00
Some checks are pending
Tests / Change detection (push) Waiting to run
Tests / Docs (push) Blocked by required conditions
Tests / Check if Autoconf files are up to date (push) Blocked by required conditions
Tests / Windows MSI (push) Blocked by required conditions
Tests / Check if generated files are up to date (push) Blocked by required conditions
Tests / (push) Blocked by required conditions
Tests / Ubuntu SSL tests with OpenSSL (push) Blocked by required conditions
Tests / Ubuntu SSL tests with AWS-LC (push) Blocked by required conditions
Tests / Android (aarch64) (push) Blocked by required conditions
Tests / Android (x86_64) (push) Blocked by required conditions
Tests / WASI (push) Blocked by required conditions
Tests / Hypothesis tests on Ubuntu (push) Blocked by required conditions
Tests / Address sanitizer (push) Blocked by required conditions
Tests / Sanitizers (push) Blocked by required conditions
Tests / Cross build Linux (push) Blocked by required conditions
Tests / CIFuzz (push) Blocked by required conditions
Tests / All required checks pass (push) Blocked by required conditions
Lint / lint (push) Waiting to run
mypy / Run mypy on Lib/_pyrepl (push) Waiting to run
mypy / Run mypy on Lib/test/libregrtest (push) Waiting to run
mypy / Run mypy on Lib/tomllib (push) Waiting to run
mypy / Run mypy on Tools/build (push) Waiting to run
mypy / Run mypy on Tools/cases_generator (push) Waiting to run
mypy / Run mypy on Tools/clinic (push) Waiting to run
mypy / Run mypy on Tools/jit (push) Waiting to run
mypy / Run mypy on Tools/peg_generator (push) Waiting to run
70 lines
1.9 KiB
C
70 lines
1.9 KiB
C
#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]
|
|
@critical_section candidates
|
|
_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=92861a6c9bd8f667]*/
|
|
{
|
|
// Check if dir is a list
|
|
if (!PyList_CheckExact(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_GET_ITEM(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 PyModuleDef_Slot module_slots[] = {
|
|
{Py_mod_multiple_interpreters, Py_MOD_MULTIPLE_INTERPRETERS_NOT_SUPPORTED},
|
|
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
|
|
{0, NULL},
|
|
};
|
|
|
|
static struct PyModuleDef suggestions_module = {
|
|
PyModuleDef_HEAD_INIT,
|
|
"_suggestions",
|
|
NULL,
|
|
0,
|
|
module_methods,
|
|
module_slots,
|
|
};
|
|
|
|
PyMODINIT_FUNC PyInit__suggestions(void) {
|
|
return PyModuleDef_Init(&suggestions_module);
|
|
}
|