summaryrefslogtreecommitdiffstats
path: root/Python/suggestions.c
Commit message (Collapse)AuthorAgeFilesLines
* gh-108511: Add C API functions which do not silently ignore errors (GH-109025)Serhiy Storchaka2023-09-171-4/+2
| | | | | | | | | Add the following functions: * PyObject_HasAttrWithError() * PyObject_HasAttrStringWithError() * PyMapping_HasKeyWithError() * PyMapping_HasKeyStringWithError()
* gh-108765: Cleanup #include in Python/*.c files (#108977)Victor Stinner2023-09-061-4/+3
| | | Mention one symbol imported by each #include.
* gh-107944: Improve error message for function calls with bad keyword ↵Pablo Galindo Salgado2023-08-171-7/+7
| | | | arguments (#107969)
* gh-106521: Remove _PyObject_LookupAttr() function (GH-106642)Serhiy Storchaka2023-07-121-1/+1
|
* gh-106030: Miscellaneous fixes in Python/suggestions.c (GH-106031)Serhiy Storchaka2023-06-231-15/+27
| | | | | | | | | | * PyDict_GetItem() and PyObject_HasAttr() suppress arbitrary errors and should not be used. * PyUnicode_CompareWithASCIIString() only works if the second argument is ASCII string. * Refleak in get_suggestions_for_name_error. * Use of borrowed pointer after possible freeing (self). * Add some missing error checks.
* GH-81057: remove static state from suggestions.c (#99411)Kumar Aditya2022-11-301-8/+19
|
* gh-99300: Use Py_NewRef() in Python/ directory (#99302)Victor Stinner2022-11-101-2/+1
| | | | Replace Py_INCREF() and Py_XINCREF() with Py_NewRef() and Py_XNewRef() in C files of the Python/ directory.
* gh-90868: Adjust the Generated Objects (gh-99223)Eric Snow2022-11-081-1/+2
| | | | | | | | | | | We do the following: * move the generated _PyUnicode_InitStaticStrings() to its own file * move the generated _PyStaticObjects_CheckRefcnt() to its own file * include pycore_global_objects.h in extension modules instead of pycore_runtime_init.h These changes help us avoid including things that aren't needed. https://github.com/python/cpython/issues/90868
* gh-99139: Improve NameError error suggestion for instances (#99140)Pablo Galindo Salgado2022-11-061-0/+23
|
* gh-91058: Add error suggestions to 'import from' import errors (#98305)Pablo Galindo Salgado2022-10-251-0/+34
|
* gh-98254: Include stdlib module names in error messages for NameErrors (#98255)Pablo Galindo Salgado2022-10-151-23/+74
|
* gh-93937, C API: Move PyFrame_GetBack() to Python.h (#93938)Victor Stinner2022-06-191-1/+0
| | | | | | | | | | | | | | | | Move the follow functions and type from frameobject.h to pyframe.h, so the standard <Python.h> provide frame getter functions: * PyFrame_Check() * PyFrame_GetBack() * PyFrame_GetBuiltins() * PyFrame_GetGenerator() * PyFrame_GetGlobals() * PyFrame_GetLasti() * PyFrame_GetLocals() * PyFrame_Type Remove #include "frameobject.h" from many C files. It's no longer needed.
* suggestions.c: Improve efficiency of levenshtein_distance method (#91835)Pieter Eendebak2022-05-021-1/+3
|
* bpo-45826: Fix a crash in suggestions.c by checking for `traceback is None` ↵Dennis Sweeney2021-11-171-3/+11
| | | | (GH-29590)
* bpo-44590: Lazily allocate frame objects (GH-27077)Mark Shannon2021-07-261-2/+2
| | | | | | | | | | | | | | * Convert "specials" array to InterpreterFrame struct, adding f_lasti, f_state and other non-debug FrameObject fields to it. * Refactor, calls pushing the call to the interpreter upward toward _PyEval_Vector. * Compute f_back when on thread stack, only filling in value when frame object outlives stack invocation. * Move ownership of InterpreterFrame in generator from frame object to generator object. * Do not create frame objects for Python calls. * Do not create frame objects for generators.
* bpo-44655: Don't include suggestions for attributes that are the same as the ↵Pablo Galindo Salgado2021-07-161-0/+3
| | | | missing one (GH-27197)
* bpo-43693: Un-revert commits 2c1e258 and b2bf2bc. (gh-26577)Eric Snow2021-06-071-2/+8
| | | | | | | | | | These were reverted in gh-26530 (commit 17c4edc) due to refleaks. * 2c1e258 - Compute deref offsets in compiler (gh-25152) * b2bf2bc - Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388) This change fixes the refleaks. https://bugs.python.org/issue43693
* bpo-43693: Revert commits 2c1e2583fdc4db6b43d163239ea42b0e8394171f and ↵Pablo Galindo2021-06-041-7/+2
| | | | | | | | | | | | | b2bf2bc1ece673d387341e06c8d3c2bc6e259747 (GH-26530) * Revert "bpo-43693: Compute deref offsets in compiler (gh-25152)" This reverts commit b2bf2bc1ece673d387341e06c8d3c2bc6e259747. * Revert "bpo-43693: Add new internal code objects fields: co_fastlocalnames and co_fastlocalkinds. (gh-26388)" This reverts commit 2c1e2583fdc4db6b43d163239ea42b0e8394171f. These two commits are breaking the refleak buildbots.
* bpo-43693: Add new internal code objects fields: co_fastlocalnames and ↵Eric Snow2021-06-031-2/+7
| | | | | | | | | | | | | | | | | co_fastlocalkinds. (gh-26388) A number of places in the code base (notably ceval.c and frameobject.c) rely on mapping variable names to indices in the frame "locals plus" array (AKA fast locals), and thus opargs. Currently the compiler indirectly encodes that information on the code object as the tuples co_varnames, co_cellvars, and co_freevars. At runtime the dependent code must calculate the proper mapping from those, which isn't ideal and impacts performance-sensitive sections. This is something we can easily address in the compiler instead. This change addresses the situation by replacing internal use of co_varnames, etc. with a single combined tuple of names in locals-plus order, along with a minimal array mapping each to its kind (local vs. cell vs. free). These two new PyCodeObject fields, co_fastlocalnames and co_fastllocalkinds, are not exposed to Python code for now, but co_varnames, etc. are still available with the same values as before (though computed lazily). Aside from the (mild) performance impact, there are a number of other benefits: * there's now a clear, direct relationship between locals-plus and variables * code that relies on the locals-plus-to-name mapping is simpler * marshaled code objects are smaller and serialize/de-serialize faster Also note that we can take this approach further by expanding the possible values in co_fastlocalkinds to include specific argument types (e.g. positional-only, kwargs). Doing so would allow further speed-ups in _PyEval_MakeFrameVector(), which is where args get unpacked into the locals-plus array. It would also allow us to shrink marshaled code objects even further. https://bugs.python.org/issue43693
* bpo-44032: Move data stack to thread from FrameObject. (GH-26076)Mark Shannon2021-05-211-3/+5
| | | | | | | | | | | | | | | | * Remove 'zombie' frames. We won't need them once we are allocating fixed-size frames. * Add co_nlocalplus field to code object to avoid recomputing size of locals + frees + cells. * Move locals, cells and freevars out of frame object into separate memory buffer. * Use per-threadstate allocated memory chunks for local variables. * Move globals and builtins from frame object to per-thread stack. * Move (slow) locals frame object to per-thread stack. * Move internal frame functions to internal header.
* bpo-38530: Refactor and improve AttributeError suggestions (GH-25776)Dennis Sweeney2021-05-031-59/+130
| | | | | | | | | | | | | | | | | | | | - Make case-swaps half the cost of any other edit - Refactor Levenshtein code to not use memory allocator, and to bail early on no match. - Add comments to Levenshtein distance code - Add test cases for Levenshtein distance behind a debug macro - Set threshold to `(name_size + item_size + 3) * MOVE_COST / 6`. - Reasoning: similar to `difflib.SequenceMatcher.ratio()` >= 2/3: ``` "Multiset Jaccard similarity" >= 2/3 matching letters / total letters >= 2/3 (name_size - distance + item_size - distance) / (name_size + item_size) >= 2/3 1 - (2*distance) / (name_size + item_size) >= 2/3 1/3 >= (2*distance) / (name_size + item_size) (name_size + item_size) / 6 >= distance With rounding: (name_size + item_size + 3) // 6 >= distance ``` Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
* bpo-38530: Require 50% similarity in NameError and AttributeError ↵Dennis Sweeney2021-04-271-1/+4
| | | | suggestions (GH-25584)
* bpo-38530: Cover more error paths in error suggestion functions (GH-25462)Pablo Galindo2021-04-171-2/+5
|
* bpo-38530: Include builtins in NameError suggestions (GH-25460)Pablo Galindo2021-04-171-1/+11
|
* bpo-38530: Match exactly AttributeError and NameError when offering ↵Pablo Galindo2021-04-161-2/+2
| | | | suggestions (GH-25443)
* bpo-38530: Optimize the calculation of string sizes when offering ↵Pablo Galindo2021-04-141-8/+10
| | | | suggestions (GH-25412)
* bpo-38530: Make sure that failing to generate suggestions on failure will ↵Pablo Galindo2021-04-141-7/+3
| | | | not propagate exceptions (GH-25408)
* bpo-38530: Offer suggestions on NameError (GH-25397)Pablo Galindo2021-04-141-8/+55
| | | | | | | | | | | When printing NameError raised by the interpreter, PyErr_Display will offer suggestions of simmilar variable names in the function that the exception was raised from: >>> schwarzschild_black_hole = None >>> schwarschild_black_hole Traceback (most recent call last): File "<stdin>", line 1, in <module> NameError: name 'schwarschild_black_hole' is not defined. Did you mean: schwarzschild_black_hole?
* bpo-38530: Offer suggestions on AttributeError (#16856)Pablo Galindo2021-04-141-0/+146
When printing AttributeError, PyErr_Display will offer suggestions of similar attribute names in the object that the exception was raised from: >>> collections.namedtoplo Traceback (most recent call last): File "<stdin>", line 1, in <module> AttributeError: module 'collections' has no attribute 'namedtoplo'. Did you mean: namedtuple?