Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
bpo-43950: Add documentation for PEP-657#27047
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Uh oh!
There was an error while loading. Please reload this page.
Merged
Changes from all commits
Commits
Show all changes
14 commits Select commit Hold shift + click to select a range
13f6258 bpo-43950: Add documentation for PEP-657
ammaraskar fcc9b93 Update for new subscript specialized traceback
ammaraskar 577d0fa Add example of binop specialization
ammaraskar 32e1a54 Add return value for failure
ammaraskar 835d086 Update Doc/whatsnew/3.11.rst
pablogsal 27e5ba5 Add note about memory usage in whatsnew
ammaraskar 23d962d Reword note with Pablo's suggestion
ammaraskar f69904f Copy note to codeobject docs
ammaraskar 6378690 Update Doc/whatsnew/3.11.rst
pablogsal 997bad4 Update Doc/reference/datamodel.rst
pablogsal 2ba721d Update Doc/reference/datamodel.rst
pablogsal c65c283 Update Doc/reference/datamodel.rst
pablogsal 0ca45fc Update Doc/whatsnew/3.11.rst
pablogsal 95048a5 Update Doc/whatsnew/3.11.rst
pablogsal File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -70,6 +70,83 @@ Summary -- Release highlights | ||
| New Features | ||
| ============ | ||
| .. _whatsnew311-pep657: | ||
| Enhanced error locations in tracebacks | ||
ammaraskar marked this conversation as resolved. Outdated Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| -------------------------------------- | ||
ammaraskar marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| When printing tracebacks, the interpreter will now point to the exact expression | ||
| that caused the error instead of just the line. For example: | ||
| .. code-block:: python | ||
| Traceback (most recent call last): | ||
| File "distance.py", line 11, in <module> | ||
| print(manhattan_distance(p1, p2)) | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| File "distance.py", line 6, in manhattan_distance | ||
| return abs(point_1.x - point_2.x) + abs(point_1.y - point_2.y) | ||
| ^^^^^^^^^ | ||
| AttributeError: 'NoneType' object has no attribute 'x' | ||
| Previous versions of the interpreter would point to just the line making it | ||
| ambiguous which object was ``None``. These enhanced errors can also be helpful | ||
| when dealing with deeply nested dictionary objects and multiple function calls, | ||
| .. code-block:: python | ||
| Traceback (most recent call last): | ||
| File "query.py", line 37, in <module> | ||
| magic_arithmetic('foo') | ||
| ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| File "query.py", line 18, in magic_arithmetic | ||
| return add_counts(x) / 25 | ||
| ^^^^^^^^^^^^^ | ||
| File "query.py", line 24, in add_counts | ||
| return 25 + query_user(user1) + query_user(user2) | ||
| ^^^^^^^^^^^^^^^^^ | ||
| File "query.py", line 32, in query_user | ||
| return 1 + query_count(db, response['a']['b']['c']['user'], retry=True) | ||
| ~~~~~~~~~~~~~~~~~~^^^^^ | ||
| TypeError: 'NoneType' object is not subscriptable | ||
isidentical marked this conversation as resolved. Outdated Show resolvedHide resolvedUh oh!There was an error while loading. Please reload this page. | ||
| as well as complex arithmetic expressions: | ||
| .. code-block:: python | ||
| Traceback (most recent call last): | ||
| File "calculation.py", line 54, in <module> | ||
| result = (x / y / z) * (a / b / c) | ||
| ~~~~~~^~~ | ||
| ZeroDivisionError: division by zero | ||
| See :pep:`657` for more details. (Contributed by Pablo Galindo, Batuhan Taskaya | ||
| and Ammar Askar in :issue:`43950`.) | ||
| .. note:: | ||
| This feature requires storing column positions in code objects which may | ||
| result in a small increase of disk usage of compiled Python files or | ||
| interpreter memory usage. To avoid storing the extra information and/or | ||
| deactivate printing the extra traceback information, the | ||
| :option:`-X` ``no_debug_ranges`` command line flag or the :envvar:`PYTHONNODEBUGRANGES` | ||
| environment variable can be used. | ||
| Column information for code objects | ||
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
| The information used by the enhanced traceback feature is made available as a | ||
| general API that can be used to correlate bytecode instructions with source | ||
| code. This information can be retrieved using: | ||
| - The :meth:`codeobject.co_positions` method in Python. | ||
| - The :c:func:`PyCode_Addr2Location` function in the C-API. | ||
| The :option:`-X` ``no_debug_ranges`` option and the environment variable | ||
| :envvar:`PYTHONNODEBUGRANGES` can be used to disable this feature. | ||
| See :pep:`657` for more details. (Contributed by Pablo Galindo, Batuhan Taskaya | ||
| and Ammar Askar in :issue:`43950`.) | ||
| Other Language Changes | ||
6 changes: 6 additions & 0 deletions 6 Misc/NEWS.d/next/Core and Builtins/2021-07-06-15-27-11.bpo-43950.LhL2-q.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| Code objects can now provide the column information for instructions when | ||
| available. This is levaraged during traceback printing to show the | ||
| expressions responsible for errors. | ||
| Contributed by Pablo Galindo, Batuhan Taskaya and Ammar Askar as part of | ||
| :pep:`657`. |
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.