pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/python/cpython/commit/a03ec20bcdf757138557127689405b3a525b3c44

97560d244c08.css" /> gh-110721: Remove unused code from suggestions.c after moving PyErr_D… · python/cpython@a03ec20 · GitHub
Skip to content

Commit a03ec20

Browse files
authored
gh-110721: Remove unused code from suggestions.c after moving PyErr_Display to use the traceback module (#113712)
1 parent 802d495 commit a03ec20

12 files changed

+117
-225
lines changed

Include/internal/pycore_global_objects_fini_generated.h

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_global_strings.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,6 @@ struct _Py_global_strings {
653653
STRUCT_FOR_ID(seek)
654654
STRUCT_FOR_ID(seekable)
655655
STRUCT_FOR_ID(selectors)
656-
STRUCT_FOR_ID(self)
657656
STRUCT_FOR_ID(send)
658657
STRUCT_FOR_ID(sep)
659658
STRUCT_FOR_ID(sequence)

Include/internal/pycore_runtime_init_generated.h

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_unicodeobject_generated.h

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Lib/traceback.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,6 +1497,13 @@ def _compute_suggestion_error(exc_value, tb, wrong_name):
14971497
if hasattr(self, wrong_name):
14981498
return f"self.{wrong_name}"
14991499

1500+
try:
1501+
import _suggestions
1502+
except ImportError:
1503+
pass
1504+
else:
1505+
return _suggestions._generate_suggestions(d, wrong_name)
1506+
15001507
# Compute closest match
15011508

15021509
if len(d) > _MAX_CANDIDATE_ITEMS:

Modules/Setup.bootstrap.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ faulthandler faulthandler.c
1111
posix posixmodule.c
1212
_signal signalmodule.c
1313
_tracemalloc _tracemalloc.c
14+
_suggestions _suggestions.c
1415

1516
# modules used by importlib, deepfreeze, freeze, runpy, and sysconfig
1617
_codecs _codecsmodule.c

Modules/_suggestions.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#include "Python.h"
2+
#include "pycore_pyerrors.h"
3+
#include "clinic/_suggestions.c.h"
4+
5+
/*[clinic input]
6+
module _suggestions
7+
[clinic start generated code]*/
8+
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e58d81fafad5637b]*/
9+
10+
/*[clinic input]
11+
_suggestions._generate_suggestions
12+
candidates: object
13+
item: unicode
14+
/
15+
Returns the candidate in candidates that's closest to item
16+
[clinic start generated code]*/
17+
18+
static PyObject *
19+
_suggestions__generate_suggestions_impl(PyObject *module,
20+
PyObject *candidates, PyObject *item)
21+
/*[clinic end generated code: output=79be7b653ae5e7ca input=ba2a8dddc654e33a]*/
22+
{
23+
// Check if dir is a list
24+
if (!PyList_Check(candidates)) {
25+
PyErr_SetString(PyExc_TypeError, "candidates must be a list");
26+
return NULL;
27+
}
28+
29+
// Check if all elements in the list are Unicode
30+
Py_ssize_t size = PyList_Size(candidates);
31+
for (Py_ssize_t i = 0; i < size; ++i) {
32+
PyObject *elem = PyList_GetItem(candidates, i);
33+
if (!PyUnicode_Check(elem)) {
34+
PyErr_SetString(PyExc_TypeError, "all elements in 'candidates' must be strings");
35+
return NULL;
36+
}
37+
}
38+
39+
PyObject* result = _Py_CalculateSuggestions(candidates, item);
40+
if (!result && !PyErr_Occurred()) {
41+
Py_RETURN_NONE;
42+
}
43+
return result;
44+
}
45+
46+
47+
static PyMethodDef module_methods[] = {
48+
_SUGGESTIONS__GENERATE_SUGGESTIONS_METHODDEF
49+
{NULL, NULL, 0, NULL} // Sentinel
50+
};
51+
52+
static struct PyModuleDef suggestions_module = {
53+
PyModuleDef_HEAD_INIT,
54+
"_suggestions",
55+
NULL,
56+
-1,
57+
module_methods
58+
};
59+
60+
PyMODINIT_FUNC PyInit__suggestions(void) {
61+
return PyModule_Create(&suggestions_module);
62+
}
63+

Modules/clinic/_suggestions.c.h

Lines changed: 41 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

PCbuild/pythoncore.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@
424424
<ClInclude Include="..\Modules\_sre\sre_lib.h" />
425425
<ClCompile Include="..\Modules\_stat.c" />
426426
<ClCompile Include="..\Modules\_struct.c" />
427+
<ClCompile Include="..\Modules\_suggestions.c" />
427428
<ClCompile Include="..\Modules\_weakref.c" />
428429
<ClCompile Include="..\Modules\arraymodule.c" />
429430
<ClCompile Include="..\Modules\atexitmodule.c" />

PCbuild/pythoncore.vcxproj.filters

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -932,6 +932,9 @@
932932
<ClCompile Include="..\Modules\_struct.c">
933933
<Filter>Modules</Filter>
934934
</ClCompile>
935+
<ClCompile Include="..\Modules\_suggestions.c">
936+
<Filter>Modules</Filter>
937+
</ClCompile>
935938
<ClCompile Include="..\Modules\_weakref.c">
936939
<Filter>Modules</Filter>
937940
</ClCompile>

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy