summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_exceptions.py
Commit message (Collapse)AuthorAgeFilesLines
* bpo-34013: Don't consider a grouped expression when reporting legacy print ↵Miss Islington (bot)2021-08-011-0/+9
| | | | | | | syntax errors (GH-27521) (cherry picked from commit 208a7e957b812ad3b3733791845447677a704f3e) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* bpo-34013: Move the Python 2 hints from the exception constructor to the ↵Miss Islington (bot)2021-07-271-7/+5
| | | | | | | parser (GH-27392) (cherry picked from commit ecc3c8e4216958d85385bf2467441c975128f26c) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* [3.10] bpo-34013: Generalize the invalid legacy statement error message ↵Pablo Galindo Salgado2021-07-271-0/+6
| | | | | | | (GH-27389). (GH-27391) (cherry picked from commit 6948964ecf94e858448dd28eea634317226d2913) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* bpo-44655: Don't include suggestions for attributes that are the same as the ↵Miss Islington (bot)2021-07-161-0/+12
| | | | | | | missing one (GH-27197) (GH-27198) (cherry picked from commit 6714dec5e104bdee4a0ed4d9966de27d1bfa1e3d) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* bpo-44317: Improve tokenizer errors with more informative locations ↵Miss Islington (bot)2021-07-101-2/+2
| | | | | | | (GH-26555) (GH-27079) (cherry picked from commit f24777c2b329974b69d2a3bf5cfc37e0fcace36c) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
* bpo-44297: Add a regression test for line numbers in with statements (GH-26891)Mark Shannon2021-06-241-7/+24
|
* bpo-44409: Fix error location in tokenizer errors that happen during ↵Miss Islington (bot)2021-06-141-0/+1
| | | | | | | initialization (GH-26712) (cherry picked from commit 507ed6fa1d6661e0f8e6d3282764aa9625a99594) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-44368: Ensure we don't raise incorrect custom syntax errors with soft ↵Miss Islington (bot)2021-06-091-0/+1
| | | | | | | keywords (GH-26630) (cherry picked from commit 457ce60fc70f1c9290023f46fb82b6a490dff32e) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-44349: Fix edge case when displaying text from files with encoding in ↵Miss Islington (bot)2021-06-091-0/+16
| | | | | | | | | syntax errors (GH-26611) (GH-26616) (cherry picked from commit 9fd21f649d66dcb10108ee395fd68ed32c8239cd) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com> Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-44335: Fix a regression when identifying invalid characters in syntax ↵Miss Islington (bot)2021-06-081-0/+1
| | | | | | | errors (GH-26589) (cherry picked from commit d334c73b56756e90c33ce06e3a6ec23271aa099d) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-44180: Report generic syntax errors in the furthest position reached in ↵Miss Islington (bot)2021-05-211-0/+1
| | | | | | | the first parser pass (GH-26253) (GH-26281) (cherry picked from commit b51081c1a8cf01b92ba0692173e1b9274a57f455) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* bpo-44143: Fix crash in the parser when raising tokenizer errors with an ↵Miss Islington (bot)2021-05-151-0/+1
| | | | | | | exception set (GH-26144) (GH-26148) (cherry picked from commit 80b089179fa798c8ceaab2ff699c82499b2fcacd) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* Correct location for syntax error in try-except (GH-25939)Mark Shannon2021-05-061-1/+1
|
* bpo-43822: Prioritize tokenizer errors over custom syntax errors when ↵Miss Islington (bot)2021-05-041-1/+1
| | | | | | | raising parser exceptions (GH-25866) (cherry picked from commit 9142088e7454a392b69a627863b235ecc32aea54) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
* 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.