Commit Graph

185 Commits

Author SHA1 Message Date
Stan Ulbrych f0aeabc6f9 gh-140049: Colorize exception notes in traceback.py (#140051)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2026-03-22 08:54:43 +00:00
Pablo Galindo Salgado 2f4eb34bd2 gh-146171: Fix nested AttributeError suggestions (#146188) 2026-03-20 12:47:59 +00:00
Bénédikt Tran 4722202a1a gh-139933: correctly suggest attributes for classes with a custom __dir__ (GH-139950)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2026-03-11 15:30:09 +01:00
Filipe Laíns 1ac9d138ae GH-145006: add ModuleNotFoundError hints when a module for a differen… (#145007)
* GH-145006: add ModuleNotFoundError hints when a module for a different ABI exists

Signed-off-by: Filipe Laíns <lains@riseup.net>

* Fix deprecation warnings

Signed-off-by: Filipe Laíns <lains@riseup.net>

* Use SHLIB_SUFFIX in test_find_incompatible_extension_modules when available

Signed-off-by: Filipe Laíns <lains@riseup.net>

* Add test_incompatible_extension_modules_hint

Signed-off-by: Filipe Laíns <lains@riseup.net>

* Fix Windows

Signed-off-by: Filipe Laíns <lains@riseup.net>

* Show the whole extension module file name in hint

Signed-off-by: Filipe Laíns <lains@riseup.net>

---------

Signed-off-by: Filipe Laíns <lains@riseup.net>
2026-02-25 00:53:01 +00:00
Filipe Laíns f282f7aed9 GH-134872: add ModuleNotFoundError suggestions (#142512)
* gh-134872: Add traceback suggestions for ModuleNotFoundError

Signed-off-by: Filipe Laíns <lains@riseup.net>

* Add news

Signed-off-by: Filipe Laíns <lains@riseup.net>

---------

Signed-off-by: Filipe Laíns <lains@riseup.net>
2026-02-19 16:10:58 +00:00
Bartosz Sławecki b6b72e7663 gh-144285: Improve AttributeError attribute suggestions (#144299) 2026-02-12 14:12:49 +00:00
Pablo Galindo Salgado 46d5106cfa gh-142349: Implement PEP 810 - Explicit lazy imports (#142351)
Co-authored-by: T. Wouters <twouters@meta.com >
Co-authored-by: Brittany Reynoso <breynoso@meta.com>
Co-authored-by: Dino Viehland <dinoviehland@meta.com>
2026-02-12 00:15:33 +00:00
Serhiy Storchaka dd0fde58cc gh-143962: Improve name suggestions for not normalized names (GH-144154)
Suggest the normalized name or the closest name to the normalized name.
If the suggested name is not ASCII, include also its ASCII representation.
2026-02-04 17:23:09 +00:00
Stan Ulbrych b52e8ce4af gh-142539: Fix traceback caret location calculation for SyntaxErrors with wide chars (#142540) 2025-12-11 04:20:55 +00:00
Pablo Galindo Salgado ed4f78a4b3 gh-142236: Fix incorrect keyword suggestions for syntax errors (#142328)
The keyword typo suggestion mechanism in traceback would incorrectly
suggest replacements when the extracted source code was merely incomplete
rather than containing an actual typo. For example, when a missing comma
caused a syntax error, the system would suggest replacing 'print' with
'not' because the incomplete code snippet happened to pass validation.

The fix adds a validation step that first checks whether the original
extracted code raises a SyntaxError. If the code compiles successfully
or is simply incomplete (compile_command returns None), the function
returns early since there is no way to verify that a keyword replacement
would actually fix the problem.
2025-12-06 21:09:35 +00:00
Stan Ulbrych d4fa70706c gh-139707: Add mechanism for distributors to supply error messages for missing stdlib modules (GH-140783) 2025-12-01 14:36:17 +01:00
Stan Ulbrych 47d2f68df2 gh-139707: Better ModuleNotFoundError message for missing stdlib modules (GH-140219) 2025-10-21 09:12:04 +02:00
yihong e18dda96c9 gh-139374: colorize traceback when using timeit command-line interface (#139375)
---------

Signed-off-by: yihong0618 <zouzou0208@gmail.com>
Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
2025-09-28 11:49:18 +00:00
Pablo Galindo Salgado 539a4ca1b9 gh-137967: Restore suggestions on nested attribute access (#137968) 2025-08-21 16:56:57 +01:00
Pablo Galindo Salgado 4e08a9f97a gh-137078: Fix keyword typo recognition when executed over files (#137079) 2025-08-15 15:14:13 +00:00
adam j hartz 04f8ef663b gh-137576: Fix for Basic REPL showing incorrect code in tracebacks with PYTHONSTARTUP (#137625)
Co-authored-by: Kirill Podoprigora <kirill.bast9@mail.ru>
2025-08-14 20:58:11 +03:00
Peter Bierma e8251dc0ae gh-134170: Add colorization to unraisable exceptions (#134183)
Default implementation of sys.unraisablehook() now uses traceback._print_exception_bltin() to print exceptions with colorized text.

Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-08-04 14:35:00 +00:00
MonadChains 18a7f5dad8 gh-127598: Improve ModuleNotFoundError when -S is passed (GH-136821) 2025-07-20 15:33:58 +02:00
Ole Herman Schumacher Elgesem 180b3eb697 fix traceback.FrameSummary docstring by adding end_lineno, colno, and end_colno (#136716) 2025-07-16 22:59:30 +05:30
devdanzin baccfdb3d4 gh-130999: Avoid exiting the new REPL when there are non-string candidates for suggestions (gh-131001) 2025-06-02 13:04:59 +02:00
Łukasz Langa f610bbdf74 gh-133346: Make theming support in _colorize extensible (GH-133347)
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
2025-05-05 23:45:25 +02:00
sobolevn 641253cfac gh-132385: Fix instance error suggestions trigger potential exceptions in traceback (#132387) 2025-05-02 15:52:59 +03:00
Pablo Galindo Salgado 32c4bbe834 gh-132449: Improve the algorithm to detect typos in keywords (#132837) 2025-04-23 14:45:18 +01:00
Pablo Galindo Salgado bf3a0a1c0f gh-132449: Improve syntax error messages for keywords with typos (#132450)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2025-04-22 11:01:55 +02:00
Duprat 69cda31261 gh-132308: prevent TracebackException swallowing attributes of a falsey Exception or ExceptionGroup (#132363) 2025-04-19 09:49:18 +00:00
Pablo Galindo Salgado a931a8b324 gh-117174: Add a new route in linecache to fetch interactive source code (#117500) 2025-03-10 21:54:05 +00:00
Irit Katriel 6c982aeb54 gh-130250: fix regression in traceback.print_last (#130318) 2025-02-19 21:44:35 +00:00
Ammar Askar f9a7d41bac gh-96092: Fix traceback.walk_stack(None) skipping too many frames (#129330)
As it says in its documentation, walk_stack was meant to just
follow `f.f_back` like other functions in the traceback module.
Instead it was previously doing `f.f_back.f_back` and then this
changed to `f_back.f_back.f_back.f_back' in Python 3.11 breaking
its behavior for external users.

This happened because the walk_stack function never really had
any good direct tests and its only consumer in the traceback module was
`extract_stack` which passed the result into `StackSummary.extract`.
As a generator, it was previously capturing the state of the stack
when it was first iterated over, rather than the stack when `walk_stack`
was called. Meaning when called inside the two method deep
`extract` and `extract_stack` calls, two `f_back`s were needed.
When 3.11 modified the sequence of calls in `extract`, two more
`f_back`s were needed to make the tests happy.

This changes the generator to capture the stack when `walk_stack` is
called, rather than when it is first iterated over. Since this is
technically a breaking change in behavior, there is a versionchanged
to the documentation. In practice, this is unlikely to break anyone,
you would have been needing to store the result of `walk_stack` and
expecting it to change.
2025-02-13 01:43:09 +00:00
sobolevn a16ded10ad gh-128894: Fix TracebackException._format_syntax_error on custom SyntaxError metadata (#128946) 2025-01-22 12:47:03 +00:00
Hugo van Kemenade 6f167d7134 gh-128595: Default to stdout isatty for colour detection instead of stderr (#128498)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
2025-01-20 12:52:42 +02:00
Tomas R. 8ba9f5bca9 gh-127347: Document traceback.print_list (#127348)
Previously, `traceback.print_list` didn't have a documentation entry and was not exposed in `traceback.__all__`. Now it has a documentation entry and is exposed in `__all__`.
2024-12-03 18:08:39 +02:00
Bogdan Romanyuk 51b012b2a8 gh-125593: Use colors to highlight error locations in tracebacks from exception group (#125681) 2024-10-27 01:57:10 +01:00
Bénédikt Tran 5cd50cb6eb gh-122145: Handle an empty AST body when reporting tracebacks (#122161) 2024-09-18 18:42:33 +02:00
Pablo Galindo Salgado 48856ead6a gh-123123: Fix display of syntax errors covering multiple lines (#123131)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
2024-08-19 15:09:03 +00:00
Alex Waygood 4b7eb321bc gh-99180: Make StackSummary.should_show_carets private (#119554) 2024-05-25 17:08:32 +00:00
Pablo Galindo Salgado a3e4fec873 gh-118893: Evaluate all statements in the new REPL separately (#119318)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2024-05-21 23:16:56 +00:00
Serhiy Storchaka 0085c3ae8f gh-116871: Improve name suggestions in tracebacks (GH-116930)
Only include underscored names in name suggestions for AttributeError and
ImportError if the original name was underscored.
2024-05-06 15:53:15 +03:00
Pablo Galindo Salgado f27f8c790a gh-111201: A new Python REPL (GH-111567)
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
Co-authored-by: Marta Gómez Macías <mgmacias@google.com>
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
2024-05-05 21:32:23 +02:00
Hugo van Kemenade 3b3f8dea57 gh-117225: Move colorize functionality to own internal module (#118283) 2024-05-01 12:27:06 -06:00
Pablo Galindo Salgado 4a08a75cf4 gh-99180: Remove traceback anchors in return and assign statements that cover all the displayed range (#112670) 2024-05-01 14:42:10 +01:00
Pablo Galindo Salgado 345e1e04ec gh-112730: Make the test suite resilient to color-activation environment variables (#117672) 2024-04-24 21:25:22 +01:00
Hugo van Kemenade 975081b11e gh-117225: Add color to doctest output (#117583)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-04-24 14:27:40 +03:00
Jérome Perrin 04fabe22dd gh-113358: Fix rendering tracebacks with exceptions with a broken __getattr__ (GH-113359)
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
2024-01-16 09:49:24 +00:00
Pablo Galindo Salgado a03ec20bcd gh-110721: Remove unused code from suggestions.c after moving PyErr_Display to use the traceback module (#113712) 2024-01-08 15:10:45 +00:00
Pablo Galindo Salgado 16448cab44 gh-112730: Use color to highlight error locations (gh-112732)
Signed-off-by: Pablo Galindo <pablogsal@gmail.com>
Co-authored-by: Łukasz Langa <lukasz@langa.pl>
2023-12-06 23:29:54 +01:00
William Wen 939fc6d6ea gh-106922: Support multi-line error locations in traceback (attempt 2) (#112097) 2023-12-01 22:18:16 +00:00
Irit Katriel 2c68011780 gh-112332: Deprecate TracebackException.exc_type, add exc_type_str. (#112333) 2023-11-28 08:03:25 +00:00
Nikita Sobolev aa732459c5 gh-111388: Add show_group parameter to traceback.format_exception_only (#111390) 2023-10-27 11:11:26 +01:00
Batuhan Taskaya 78e6d72e38 bpo-43950: handle wide unicode characters in tracebacks (#28150) 2023-10-26 07:05:29 +00:00
Pablo Galindo Salgado 90a1b2859f gh-67224: Show source lines in tracebacks when using the -c option when running Python (#111200) 2023-10-26 15:17:28 +09:00