Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
13f6258fcc9b93577d0fa32e1a54835d08627e5ba523d962df69904f6378690997bad42ba721dc65c2830ca45fc95048a5File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| 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
Uh oh!There was an error while loading. Please reload this page. | ||
| -------------------------------------- | ||
ammaraskar marked this conversation as resolved.
Uh 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
Uh 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 | ||
| 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`. |
Uh oh!
There was an error while loading. Please reload this page.