summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_exceptions.py
Commit message (Collapse)AuthorAgeFilesLines
...
* bpo-44143: Fix crash in the parser when raising tokenizer errors with an ↵Pablo Galindo2021-05-151-0/+1
| | | | exception set (GH-26144)
* bpo-40222: "Zero cost" exception handling (GH-25729)Mark Shannon2021-05-071-1/+1
| | | | | | | | "Zero cost" exception handling. * Uses a lookup table to determine how to handle exceptions. * Removes SETUP_FINALLY and POP_TOP block instructions, eliminating (most of) the runtime overhead of try statements. * Reduces the size of the frame object by about 60%.
* bpo-43822: Prioritize tokenizer errors over custom syntax errors when ↵Pablo Galindo2021-05-041-1/+1
| | | | raising parser exceptions (GH-25866)
* bpo-38530: Refactor and improve AttributeError suggestions (GH-25776)Dennis Sweeney2021-05-031-18/+84
| | | | | | | | | | | | | | | | | | | | - 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-43933: Show frame.f_lineno as None, rather than -1, if there is no line ↵Mark Shannon2021-04-291-1/+10
| | | | number. (GH-25717)
* bpo-38530: Require 50% similarity in NameError and AttributeError ↵Dennis Sweeney2021-04-271-0/+112
| | | | suggestions (GH-25584)
* bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)Pablo Galindo2021-04-231-12/+143
| | | | | | | | | | | | | | | | | To improve the user experience understanding what part of the error messages associated with SyntaxErrors is wrong, we can highlight the whole error range and not only place the caret at the first character. In this way: >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^ SyntaxError: Generator expression must be parenthesized becomes >>> foo(x, z for z in range(10), t, w) File "<stdin>", line 1 foo(x, z for z in range(10), t, w) ^^^^^^^^^^^^^^^^^^^^ SyntaxError: Generator expression must be parenthesized
* bpo-43859: Improve the error message for IndentationError exceptions (GH-25431)Pablo Galindo2021-04-211-1/+1
|
* bpo-25460: Surround suggestions by quotes (GH-25473)Pablo Galindo2021-04-191-14/+14
|
* bpo-38530: Cover more error paths in error suggestion functions (GH-25462)Pablo Galindo2021-04-171-0/+10
|
* bpo-38530: Include builtins in NameError suggestions (GH-25460)Pablo Galindo2021-04-171-4/+20
|
* bpo-38530: Match exactly AttributeError and NameError when offering ↵Pablo Galindo2021-04-161-0/+15
| | | | suggestions (GH-25443)
* bpo-38530: Make sure that failing to generate suggestions on failure will ↵Pablo Galindo2021-04-141-0/+14
| | | | not propagate exceptions (GH-25408)
* bpo-38530: Offer suggestions on NameError (GH-25397)Pablo Galindo2021-04-141-0/+123
| | | | | | | | | | | 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/+159
| | | | | | | | | 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?
* bpo-43797: Improve syntax error for invalid comparisons (#25317)Pablo Galindo2021-04-121-1/+1
| | | | | | | | | | | | | * bpo-43797: Improve syntax error for invalid comparisons * Update Lib/test/test_fstring.py Co-authored-by: Guido van Rossum <gvanrossum@gmail.com> * Apply review comments * can't -> cannot Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
* bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25142)Inada Naoki2021-04-021-2/+2
| | | | | | | | | | | | | * test__xxsubinterpreters * test_builtin * test_doctest * test_exceptions * test_opcodes * test_support * test_argparse * test_baseexception * test_bdb * test_bool * test_asdl_parser
* bpo-40176: Improve error messages for unclosed string literals (GH-19346)Batuhan Taskaya2021-01-201-2/+2
| | | Automerge-Triggered-By: GH:isidentical
* bpo-42827: Fix crash on SyntaxError in multiline expressions (GH-24140)Lysandros Nikolaou2021-01-141-0/+3
| | | | | | | | | | | | | | | | | | | | | | | When trying to extract the error line for the error message there are two distinct cases: 1. The input comes from a file, which means that we can extract the error line by using `PyErr_ProgramTextObject` and which we already do. 2. The input does not come from a file, at which point we need to get the source code from the tokenizer: * If the tokenizer's current line number is the same with the line of the error, we get the line from `tok->buf` and we're ready. * Else, we can extract the error line from the source code in the following two ways: * If the input comes from a string we have all the input in `tok->str` and we can extract the error line from it. * If the input comes from stdin, i.e. the interactive prompt, we do not have access to the previous line. That's why a new field `tok->stdin_content` is added which holds the whole input for the current (multiline) statement or expression. We can then extract the error line from `tok->stdin_content` like we do in the string case above. Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-42246: Make sure that `f_lasti`, and thus `f_lineno`, is set correctly ↵Mark Shannon2020-12-171-0/+83
| | | | | | | | | after raising or reraising an exception (GH-23803) * Ensure that f_lasti is set correctly after an exception is raised to conform to PEP 626. * Update importlib * Add NEWS.
* bpo-30858: Improve error location for expressions with assignments (GH-23753)Pablo Galindo2020-12-131-1/+1
| | | Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
* bpo-42500: Fix recursion in or after except (GH-23568)Mark Shannon2020-12-021-2/+50
| | | * Use counter, rather boolean state when handling soft overflows.
* bpo-41659: Disallow curly brace directly after primary (GH-22996)Lysandros Nikolaou2020-10-271-0/+1
|
* bpo-41654: Fix deallocator of MemoryError to account for subclasses (GH-22020)Pablo Galindo2020-09-011-0/+31
| | | | | | | When allocating MemoryError classes, there is some logic to use pre-allocated instances in a freelist only if the type that is being allocated is not a subclass of MemoryError. Unfortunately in the destructor this logic is not present so the freelist is altered even with subclasses of MemoryError.
* bpo-40275: Use new test.support helper submodules in tests (GH-21448)Hai Shi2020-08-031-3/+6
|
* bpo-40334: Produce better error messages on invalid targets (GH-20106)Lysandros Nikolaou2020-06-181-1/+1
| | | | | | | | | | | | | | The following error messages get produced: - `cannot delete ...` for invalid `del` targets - `... is an illegal 'for' target` for invalid targets in for statements - `... is an illegal 'with' target` for invalid targets in with statements Additionally, a few `cut`s were added in various places before the invocation of the `invalid_*` rule, in order to speed things up. Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-40939: Remove the old parser (GH-20768)Pablo Galindo2020-06-111-3/+3
| | | This commit removes the old parser, the deprecated parser module, the old parser compatibility flags and environment variables and all associated support code and documentation.
* Use subTest in test_exceptions for better error reporting (GH-20140)Pablo Galindo2020-05-171-26/+29
|
* bpo-40619: Correctly handle error lines in programs without file mode (GH-20090)Pablo Galindo2020-05-141-0/+2
|
* bpo-40334: Always show the caret on SyntaxErrors (GH-20050)Lysandros Nikolaou2020-05-131-9/+6
| | | | | | | | | | | | | | This commit fixes SyntaxError locations when the caret is not displayed, by doing the following: - `col_number` always gets set to the location of the offending node/expr. When no caret is to be displayed, this gets achieved by setting the object holding the error line to None. - Introduce a new function `_PyPegen_raise_error_known_location`, which can be called, when an arbitrary `lineno`/`col_offset` needs to be passed. This function then gets used in the grammar (through some new macros and inline functions) so that SyntaxError locations of the new parser match that of the old.
* bpo-40334: Error message for invalid default args in function call (GH-19973)Lysandros Nikolaou2020-05-071-2/+2
| | | | | When parsing something like `f(g()=2)`, where the name of a default arg is not a NAME, but an arbitrary expression, a specialised error message is emitted.
* bpo-40334: Spacialized error message for invalid args after bare '*' (GH-19865)Lysandros Nikolaou2020-05-041-1/+1
| | | When parsing things like `def f(*): pass` the old parser used to output `SyntaxError: named arguments must follow bare *`, which the new parser wasn't able to do.
* bpo-40334: Improve column offsets for thrown syntax errors by Pegen (GH-19782)Batuhan Taskaya2020-05-011-21/+21
|
* bpo-40334: Rename PyConfig.use_peg to _use_peg_parser (GH-19670)Victor Stinner2020-04-231-1/+1
| | | | | | | | | | | * Rename PyConfig.use_peg to _use_peg_parser * Document PyConfig._use_peg_parser and mark it a deprecated * Mark -X oldparser option and PYTHONOLDPARSER env var as deprecated in the documentation. * Add use_old_parser() and skip_if_new_parser() to test.support * Remove sys.flags.use_peg: use_old_parser() uses _testinternalcapi.get_configs() instead. * Enhance test_embed tests * subprocess._args_from_interpreter_flags() copies -X oldparser
* bpo-40334: PEP 617 implementation: New PEG parser for CPython (GH-19503)Pablo Galindo2020-04-221-0/+1
| | | | Co-authored-by: Guido van Rossum <guido@python.org> Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
* bpo-40335: Correctly handle multi-line strings in tokenize error scenarios ↵Pablo Galindo2020-04-211-1/+11
| | | | | (GH-19619) Co-authored-by: Guido van Rossum <gvanrossum@gmail.com>
* bpo-39947: Move get_recursion_depth() to _testinternalcapi (GH-18974)Victor Stinner2020-03-131-1/+1
| | | | | Move get_recursion_depth() function from _testcapi to _testinternalcapi to avoid accessing PyThreadState attributes directly in _testcapi.
* bpo-39882: Py_FatalError() logs the function name (GH-18819)Victor Stinner2020-03-061-2/+3
| | | | | | | | | | | | The Py_FatalError() function is replaced with a macro which logs automatically the name of the current function, unless the Py_LIMITED_API macro is defined. Changes: * Add _Py_FatalErrorFunc() function. * Remove the function name from the message of Py_FatalError() calls which included the function name. * Update tests.
* bpo-39219: Fix SyntaxError attributes in the tokenizer. (GH-17828)Serhiy Storchaka2020-02-121-1/+13
| | | | * Always set the text attribute. * Correct the offset attribute for non-ascii sources.
* bpo-34880: Add the LOAD_ASSERTION_ERROR opcode. (GH-15073)Zackery Spytz2019-08-251-0/+16
| | | | Fix assert statement misbehavior if AssertionError is shadowed.
* Remove unused imports in tests (GH-14518)Victor Stinner2019-07-011-1/+1
|
* bpo-36829: Add test.support.catch_unraisable_exception() (GH-13490)Victor Stinner2019-05-221-22/+8
| | | | | | * Copy test_exceptions.test_unraisable() to test_sys.UnraisableHookTest(). * Use catch_unraisable_exception() in test_coroutines, test_exceptions, test_generators.
* bpo-31241: Fix AST node position for list and generator comprehensions. ↵Serhiy Storchaka2018-11-271-1/+1
| | | | | | | | (GH-10633) The lineno and col_offset attributes of AST nodes for list comprehensions, generator expressions and tuples are now point to the opening parenthesis or square brace. For tuples without parenthesis they point to the position of the first item.
* bpo-34683: Make SyntaxError column offsets consistently 1-indexed (gh-9338)Ammar Askar2018-09-241-0/+39
| | | | | | Also point to start of tokens in parsing errors. Fixes bpo-34683
* bpo-32489: Allow 'continue' in 'finally' clause. (GH-5822)Serhiy Storchaka2018-03-181-9/+0
|
* Fix miscellaneous typos (#4275)luzpaz2017-11-051-1/+1
|
* bpo-30697: Fix PyErr_NormalizeException() when no memory (GH-2327)xdegaye2017-10-261-2/+101
|
* bpo-30817: Fix PyErr_PrintEx() when no memory (#2526)xdegaye2017-10-231-1/+18
|
* Move exc state to generator. Fixes bpo-25612 (#1773)Mark Shannon2017-10-221-0/+56
| | | Move exception state information from frame objects to coroutine (generator/thread) object where it belongs.
* bpo-31161: only check for parens error for SyntaxError (#3082)Martijn Pieters2017-08-221-0/+28
| | | | Subclasses such as IndentError and TabError should not have this message applied.