Skip to content

gh-95913: Fix and copyedit New Features section of 3.11 What's New #95915

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
merged 5 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Doc/c-api/code.rst
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
.. highlight:: c

.. _codeobjects:

.. index:: object; code, code object

.. _codeobjects:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this change affect :ref: and index entries linking (if it does)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't affect the index entries (it still links to the same place, right above the section) but fixes an issue with the ref target not actually being the section as intended, and thus not having a generated link text causing :ref:`codeobjects` to error out. It won't affect any existing refs, since it only changes the generated link text and not the ref target location, which the existing refs could not be using or they would have errored and failed the build.

Code Objects
------------

Expand Down
71 changes: 38 additions & 33 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ This article explains the new features in Python 3.11, compared to 3.10.
For full details, see the :ref:`changelog <changelog>`.


.. _whatsnew311-summary:

Summary -- Release highlights
=============================

Expand Down Expand Up @@ -97,16 +99,18 @@ Important deprecations, removals or restrictions:
* :pep:`670`: Convert macros to functions in the Python C API.


.. _whatsnew311-features:

New Features
============

.. _whatsnew311-pep657:

Enhanced error locations in tracebacks
--------------------------------------
PEP 657: Enhanced error locations in tracebacks
-----------------------------------------------

When printing tracebacks, the interpreter will now point to the exact expression
that caused the error instead of just the line. For example:
that caused the error, instead of just the line. For example:

.. code-block:: python

Expand All @@ -119,9 +123,9 @@ that caused the error instead of just the line. For example:
^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'x'

Previous versions of the interpreter would point to just the line making it
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,
when dealing with deeply nested :class:`dict` objects and multiple function calls:

.. code-block:: python
Comment on lines +128 to 130
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we use this here?

Suggested change
when dealing with deeply nested :class:`dict` objects and multiple function calls:
.. code-block:: python
when dealing with deeply nested :class:`dict` objects and multiple function calls::

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't see a strong reason to change this from the original source, since it renders equivalently, is a little more explicit and (IIRC) warns if the syntax used doesn't actually lex according to the declared lexer (vs. :: fails silently). But I can if you think its important


Expand All @@ -139,7 +143,7 @@ when dealing with deeply nested dictionary objects and multiple function calls,
~~~~~~~~~~~~~~~~~~^^^^^
TypeError: 'NoneType' object is not subscriptable

as well as complex arithmetic expressions:
As well as complex arithmetic expressions:

.. code-block:: python
Comment on lines +146 to 148
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
As well as complex arithmetic expressions:
.. code-block:: python
As well as complex arithmetic expressions::

Same here, and possibly elsewhere.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above—I can do this if you really think its necessary, but I'm not sure it is.


Expand All @@ -149,33 +153,28 @@ as well as complex arithmetic expressions:
~~~~~~^~~
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:
Additionally, the information used by the enhanced traceback feature
is made available via a general API, that can be used to correlate
:term:`bytecode` :ref:`instructions <bytecodes>` with source code location.
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.
- The :c:func:`PyCode_Addr2Location` function in the C API.

See :pep:`657` for more details. (Contributed by Pablo Galindo, Batuhan Taskaya
and Ammar Askar in :issue:`43950`.)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
and Ammar Askar in :issue:`43950`.)
and Ammar Askar in :gh:`88116`.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above


.. note::
This feature requires storing column positions in :ref:`codeobjects`,
which may result in a small increase in interpreter memory usage
and disk usage for compiled Python files.
To avoid storing the extra information
and deactivate printing the extra traceback information,
use the :option:`-X no_debug_ranges <-X>` command line option
or the :envvar:`PYTHONNODEBUGRANGES` environment variable.


.. _whatsnew311-pep654:

PEP 654: Exception Groups and ``except*``
-----------------------------------------
Expand All @@ -193,14 +192,20 @@ See :pep:`654` for more details.
Irit Katriel, Yury Selivanov and Guido van Rossum.)


.. _whatsnew311-pep670:

PEP 678: Exceptions can be enriched with notes
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
----------------------------------------------

The :meth:`~BaseException.add_note` method is added to :exc:`BaseException`.
It can be used to enrich exceptions with context information
that is not available at the time when the exception is raised.
The added notes appear in the default traceback.

See :pep:`678` for more details.

The :meth:`add_note` method was added to :exc:`BaseException`. It can be
used to enrich exceptions with context information which is not available
at the time when the exception is raised. The notes added appear in the
default traceback. See :pep:`678` for more details. (Contributed by
Irit Katriel in :issue:`45607`.)
(Contributed by Irit Katriel in :issue:`45607`.
PEP written by Zac Hatfield-Dodds.)


.. _new-feat-related-type-hints-311:
Expand Down