Commit Graph

202 Commits

Author SHA1 Message Date
Miss Islington (bot) 1960409a6d
bpo-44895: skip test_no_hang_on_context_chain_cycle2 until the refleak is fixed (GH-27761)
(cherry picked from commit 62bc716fde)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2021-08-16 02:01:14 -07:00
Miss Islington (bot) ebc5926234
bpo-44895: Temporarily add an extra gc.collect() call (GH-27746)
This is part of an investigation of a non-deterministic reference leak. While we're looking for the root cause, this is included temporarily so that CI doesn't fail on this particular issue. This enables it to find other regressions in the meantime, which would otherwise be shadowed by our known issue.
(cherry picked from commit 7bf28cbb4b)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2021-08-13 03:21:26 -07:00
Benjamin Peterson ef36dfe4de
[3.10] bpo-33930: Fix typo in the test name. (GH-27736)
[bpo-33930](): Fix typo in the test name. (GH-27733)
(cherry picked from commit f08e6d1bb3)

Automerge-Triggered-By: GH:benjaminp
2021-08-13 02:45:13 -07:00
Miss Islington (bot) d6d2d54997
bpo-33930: Fix segfault with deep recursion when cleaning method objects (GH-27678) (GH-27719)
(cherry picked from commit bfc2d5a5c4)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-08-11 10:32:44 +02:00
Miss Islington (bot) d86bbe3cff
bpo-25782: avoid hang in PyErr_SetObject when current exception has a cycle in its context chain (GH-27626)
Co-authored-by: Dennis Sweeney 36520290+sweeneyde@users.noreply.github.com
(cherry picked from commit d5c217475c)

Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2021-08-10 06:47:23 -07:00
Miss Islington (bot) 35035bc35a
bpo-34013: Don't consider a grouped expression when reporting legacy print syntax errors (GH-27521)
(cherry picked from commit 208a7e957b)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-07-31 18:31:44 -07:00
Miss Islington (bot) 68e3dca068
bpo-34013: Move the Python 2 hints from the exception constructor to the parser (GH-27392)
(cherry picked from commit ecc3c8e421)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-07-27 14:19:18 -07:00
Pablo Galindo Salgado b977f8510e
[3.10] bpo-34013: Generalize the invalid legacy statement error message (GH-27389). (GH-27391)
(cherry picked from commit 6948964ecf)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-07-27 18:52:32 +01:00
Miss Islington (bot) a0b1d401db
bpo-44655: Don't include suggestions for attributes that are the same as the missing one (GH-27197) (GH-27198)
(cherry picked from commit 6714dec5e1)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-07-16 22:16:08 +01:00
Miss Islington (bot) 2a722d4fab
bpo-44317: Improve tokenizer errors with more informative locations (GH-26555) (GH-27079)
(cherry picked from commit f24777c2b3)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-07-10 01:47:33 +01:00
Mark Shannon 0b6b286518
bpo-44297: Add a regression test for line numbers in with statements (GH-26891) 2021-06-24 13:09:14 +01:00
Miss Islington (bot) 133cddf76e
bpo-44409: Fix error location in tokenizer errors that happen during initialization (GH-26712)
(cherry picked from commit 507ed6fa1d)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2021-06-14 10:07:52 -07:00
Miss Islington (bot) f807a4fad4
bpo-44368: Ensure we don't raise incorrect custom syntax errors with soft keywords (GH-26630)
(cherry picked from commit 457ce60fc7)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2021-06-09 14:45:43 -07:00
Miss Islington (bot) c0496093e5
bpo-44349: Fix edge case when displaying text from files with encoding in syntax errors (GH-26611) (GH-26616)
(cherry picked from commit 9fd21f649d)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2021-06-09 01:29:21 +01:00
Miss Islington (bot) 933b5b6359
bpo-44335: Fix a regression when identifying invalid characters in syntax errors (GH-26589)
(cherry picked from commit d334c73b56)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2021-06-08 04:46:56 -07:00
Miss Islington (bot) 07dba474c5
bpo-44180: Report generic syntax errors in the furthest position reached in the first parser pass (GH-26253) (GH-26281)
(cherry picked from commit b51081c1a8)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2021-05-21 16:29:58 +01:00
Miss Islington (bot) 1afaaf5a2d
bpo-44143: Fix crash in the parser when raising tokenizer errors with an exception set (GH-26144) (GH-26148)
(cherry picked from commit 80b089179f)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2021-05-15 18:39:18 +01:00
Mark Shannon 8d4b18429d
Correct location for syntax error in try-except (GH-25939) 2021-05-06 13:38:50 +01:00
Miss Islington (bot) 756b7b9248
bpo-43822: Prioritize tokenizer errors over custom syntax errors when raising parser exceptions (GH-25866)
(cherry picked from commit 9142088e74)

Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
2021-05-03 18:06:45 -07:00
Dennis Sweeney 80a2a4ed7d
bpo-38530: Refactor and improve AttributeError suggestions (GH-25776)
- 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>
2021-05-03 16:47:27 +01:00
Mark Shannon 088a15c49d
bpo-43933: Show frame.f_lineno as None, rather than -1, if there is no line number. (GH-25717) 2021-04-29 19:28:50 +01:00
Dennis Sweeney 284c52da09
bpo-38530: Require 50% similarity in NameError and AttributeError suggestions (GH-25584) 2021-04-27 01:22:27 +01:00
Pablo Galindo a77aac4fca
bpo-43914: Highlight invalid ranges in SyntaxErrors (#25525)
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
2021-04-23 14:27:05 +01:00
Pablo Galindo 56c95dfe27
bpo-43859: Improve the error message for IndentationError exceptions (GH-25431) 2021-04-21 15:28:21 +01:00
Pablo Galindo 7a04116246
bpo-25460: Surround suggestions by quotes (GH-25473) 2021-04-19 23:35:53 +01:00
Pablo Galindo 0b1c169c4a
bpo-38530: Cover more error paths in error suggestion functions (GH-25462) 2021-04-17 23:28:45 +01:00
Pablo Galindo 3ab4bea5a3
bpo-38530: Include builtins in NameError suggestions (GH-25460) 2021-04-17 22:26:54 +01:00
Pablo Galindo 0ad81d4db2
bpo-38530: Match exactly AttributeError and NameError when offering suggestions (GH-25443) 2021-04-16 17:12:03 +01:00
Pablo Galindo e07f4ab26a
bpo-38530: Make sure that failing to generate suggestions on failure will not propagate exceptions (GH-25408) 2021-04-14 18:58:28 +01:00
Pablo Galindo 5bf8bf2267
bpo-38530: Offer suggestions on NameError (GH-25397)
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?
2021-04-14 15:10:33 +01:00
Pablo Galindo 37494b441a
bpo-38530: Offer suggestions on AttributeError (#16856)
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?
2021-04-14 02:36:07 +01:00
Pablo Galindo b86ed8e3bb
bpo-43797: Improve syntax error for invalid comparisons (#25317)
* 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>
2021-04-12 16:59:30 +01:00
Inada Naoki 8bbfeb3330
bpo-43651: PEP 597: Fix EncodingWarning in some tests (GH-25142)
* test__xxsubinterpreters
* test_builtin
* test_doctest
* test_exceptions
* test_opcodes
* test_support
* test_argparse
* test_baseexception
* test_bdb
* test_bool
* test_asdl_parser
2021-04-02 12:53:46 +09:00
Batuhan Taskaya a698d52c39
bpo-40176: Improve error messages for unclosed string literals (GH-19346)
Automerge-Triggered-By: GH:isidentical
2021-01-20 13:38:47 -08:00
Lysandros Nikolaou e5fe509054
bpo-42827: Fix crash on SyntaxError in multiline expressions (GH-24140)
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>
2021-01-14 21:36:30 +00:00
Mark Shannon bf353f3c2d
bpo-42246: Make sure that `f_lasti`, and thus `f_lineno`, is set correctly 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.
2020-12-17 13:55:28 +00:00
Pablo Galindo 43c4fb6c90
bpo-30858: Improve error location for expressions with assignments (GH-23753)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
2020-12-13 16:46:48 +00:00
Mark Shannon 4e7a69bdb6
bpo-42500: Fix recursion in or after except (GH-23568)
* Use counter, rather boolean state when handling soft overflows.
2020-12-02 13:30:55 +00:00
Lysandros Nikolaou 15acc4eaba
bpo-41659: Disallow curly brace directly after primary (GH-22996) 2020-10-27 20:54:20 +02:00
Pablo Galindo 9b648a95cc
bpo-41654: Fix deallocator of MemoryError to account for subclasses (GH-22020)
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.
2020-09-01 19:39:46 +01:00
Hai Shi 4660597b51
bpo-40275: Use new test.support helper submodules in tests (GH-21448) 2020-08-03 18:49:18 +02:00
Lysandros Nikolaou 01ece63d42
bpo-40334: Produce better error messages on invalid targets (GH-20106)
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>
2020-06-19 00:10:43 +01:00
Pablo Galindo 1ed83adb0e
bpo-40939: Remove the old parser (GH-20768)
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.
2020-06-11 17:30:46 +01:00
Pablo Galindo af8e5f84d9
Use subTest in test_exceptions for better error reporting (GH-20140) 2020-05-17 01:22:00 +01:00
Pablo Galindo bcc3036095
bpo-40619: Correctly handle error lines in programs without file mode (GH-20090) 2020-05-14 21:11:48 +01:00
Lysandros Nikolaou a15c9b3a05
bpo-40334: Always show the caret on SyntaxErrors (GH-20050)
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.
2020-05-13 20:36:27 +01:00
Lysandros Nikolaou 4638c64295
bpo-40334: Error message for invalid default args in function call (GH-19973)
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.
2020-05-07 11:44:06 +01:00
Lysandros Nikolaou e10e7c771b
bpo-40334: Spacialized error message for invalid args after bare '*' (GH-19865)
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.
2020-05-04 11:58:31 +01:00
Batuhan Taskaya 76c1b4d5c5
bpo-40334: Improve column offsets for thrown syntax errors by Pegen (GH-19782) 2020-05-01 14:13:43 +01:00
Victor Stinner 1def7754b7
bpo-40334: Rename PyConfig.use_peg to _use_peg_parser (GH-19670)
* 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
2020-04-23 03:03:24 +02:00