Commit Graph

223 Commits

Author SHA1 Message Date
Miss Islington (bot) 19b94bc136
gh-96352: Set AttributeError context in _PyObject_GenericGetAttrWithDict (GH-96353)
(cherry picked from commit b9634ac776)

Co-authored-by: philg314 <110174000+philg314@users.noreply.github.com>
2022-09-08 04:46:53 -07:00
Matthieu Dartiailh 94609e3192
[3.10] Backport bpo-47212 (GH-32302) to Python 3.10 (GH-32334)
(cherry picked from commit aa0f056a00)

# Conflicts:
#	Grammar/python.gram
#	Parser/action_helpers.c

Automerge-Triggered-By: GH:pablogsal
2022-04-05 09:21:49 -07:00
Pablo Galindo Salgado 3594ebca2c
[3.10] bpo-46940: Don't override existing AttributeError suggestion information (GH-31710) (GH-31724)
When an exception is created in a nested call to PyObject_GetAttr, any
external calls will override the context information of the
AttributeError that we have already placed in the most internal call.
This will cause the suggestions we create to nor work properly as the
attribute name and object that we will be using are the incorrect ones.

To avoid this, we need to check first if these attributes are already
set and bail out if that's the case..
(cherry picked from commit 3b3be05a16)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2022-03-07 13:18:36 +00:00
Pablo Galindo Salgado 14284b0e71
[3.10] Allow the parser to avoid nested processing of invalid rules (GH-31252). (GH-31257)
(cherry picked from commit 390459de6d)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2022-02-10 14:38:31 +00:00
Pablo Galindo Salgado 633db1c4eb
[3.10] bpo-46240: Correct the error for unclosed parentheses when the tokenizer is not finished (GH-30378). (GH-30819)
(cherry picked from commit 70f415fb8b)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2022-01-23 03:10:37 +00:00
Miss Islington (bot) d4a9e34401
bpo-46442: improve and rename testExceptionCleanupNames (GH-30758)
The test tested that explicitly deleting the local variable bound to the exception
did not cause problems, but it did not test what it actually claimed to test, i.e.
that the variable is deleted automatically.
(cherry picked from commit 82c53229e1)

Co-authored-by: Yellow Dusk <yellow.dusk1590@fastmail.com>
2022-01-21 23:34:29 -08:00
Miss Islington (bot) 1fb1f5d8bd
[3.10] bpo-46339: Fix crash in the parser when computing error text for multi-line f-strings (GH-30529) (GH-30542)
* bpo-46339: Fix crash in the parser when computing error text for multi-line f-strings (GH-30529)

Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit cedec19be8)

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

* Fix interactive mode

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2022-01-20 13:05:10 +00:00
Miss Islington (bot) 19a85501ce
bpo-46237: Fix the line number of tokenizer errors inside f-strings (GH-30463)
(cherry picked from commit 6fa8b2ceee)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2022-01-11 08:33:08 -08:00
Miss Islington (bot) 94483f1e3c
bpo-46054: Fix parsing error when parsing non-utf8 characters in source files (GH-30068) (GH-30069)
(cherry picked from commit 4325a766f5)

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

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-12-12 16:52:49 +00:00
Miss Islington (bot) 438817fdd5
bpo-46042: Improve SyntaxError locations in the symbol table (GH-30059) (GH-30064)
(cherry picked from commit 59435eea08)

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

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-12-12 01:24:12 +00:00
Pablo Galindo Salgado c521412003
[3.10] bpo-46004: Fix error location for loops with invalid targets (GH-29959). (GH-29961)
(cherry picked from commit 1c7a1c3be0)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-12-07 15:23:33 +00:00
Pablo Galindo Salgado c72311d917
[3.10] bpo-45727: Only trigger the 'did you forgot a comma' error suggestion if inside parentheses. (GH-29767)
Backport of GH-29757

Co-authored-by: Pablo Galindo <pablogsal@gmail.com>
2021-11-25 01:01:40 +00:00
Pablo Galindo Salgado 511ee1c0fa
[3.10] bpo-45727: Make the syntax error for missing comma more consistent (GH-29427) (GH-29647)
(cherry picked from commit 546cefcda7)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-11-20 17:39:17 +00:00
Łukasz Langa 904af3de2b
[3.10] bpo-45848: Allow the parser to get error lines from encoded files (GH-29646) (GH-29661)
(cherry picked from commit fdcc46d955)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-11-20 16:34:56 +01:00
Łukasz Langa 8eabe60108
[3.10] bpo-45826: Fix a crash in suggestions.c by checking for `traceback is None` (GH-29590) (GH-29602)
(cherry picked from commit 5d90c467c0)

Co-authored-by: Dennis Sweeney <36520290+sweeneyde@users.noreply.github.com>
2021-11-18 01:28:04 +01:00
Łukasz Langa 5c9cab595e
[3.10] bpo-45494: Fix parser crash when reporting errors involving invalid continuation characters (GH-28993) (GH-29070)
There are two errors that this commit fixes:

* The parser was not correctly computing the offset and the string
  source for E_LINECONT errors due to the incorrect usage of strtok().
* The parser was not correctly unwinding the call stack when a tokenizer
  exception happened in rules involving optionals ('?', [...]) as we
  always make them return valid results by using the comma operator. We
  need to check first if we don't have an error before continuing..
(cherry picked from commit a106343f63)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-10-19 22:31:18 +02:00
Pablo Galindo Salgado 4ce55a2353
[3.10] bpo-45408: Don't override previous tokenizer errors in the second parser pass (GH-28812). (GH-28813)
(cherry picked from commit 0219017df7)

Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
2021-10-08 00:50:10 +01:00
Christian Clauss cfca4a6774
[3.10] Fix typos in the Lib directory (GH-28775) (GH-28804)
Fix typos in the Lib directory as identified by codespell.

Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu>.
(cherry picked from commit 745c9d9dfc)

Co-authored-by: Christian Clauss <cclauss@me.com>
2021-10-07 11:49:47 -04:00
Miss Islington (bot) d55bf81c4e
bpo-45400: Fix suggestion test of test_exceptions (GH-28783)
Fix test_name_error_suggestions_do_not_trigger_for_too_many_locals()
of test_exceptions if a directory name contains "a1" (like
"Python-3.11.0a1"): use a stricter regular expression.
(cherry picked from commit 4e605666b0)

Co-authored-by: Victor Stinner <vstinner@python.org>
2021-10-07 05:11:38 -07:00
Miss Islington (bot) c800e39094
[tests] Add missing assert against expected tracebacks in test_exceptions.py (GH-28484) (GH-28510)
(cherry picked from commit a007347100)

Co-authored-by: andrei kulakov <andrei.avk@gmail.com>
2021-09-22 00:38:59 +02:00
Serhiy Storchaka 462c1f0403
[3.10] bpo-25130: Add calls of gc.collect() in tests to support PyPy (GH-28005) (GH-28027)
(cherry picked from commit 2a8127cafe)

Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
2021-09-08 17:08:57 +02:00
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