Skip to content
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

gh-95913: Copyedit/improve Other Language Changes What's New section #97719

Merged
67 changes: 36 additions & 31 deletions Doc/whatsnew/3.11.rst
Original file line number Diff line number Diff line change
Expand Up @@ -423,52 +423,57 @@ detected by checking its tag for a ``-32`` suffix. All releases of Python
since 3.5 have included this in their 32-bit builds.


.. _whatsnew311-other-lang-changes:

Other Language Changes
======================

* Starred expressions can be used in :ref:`for statements<for>`. (See
:issue:`46725` for more details.)

* Asynchronous comprehensions are now allowed inside comprehensions in
asynchronous functions. Outer comprehensions implicitly become
asynchronous. (Contributed by Serhiy Storchaka in :issue:`33346`.)
* Starred unpacking expressions can now be used in :keyword:`for` statements.
(See :issue:`46725` for more details.)

* A :exc:`TypeError` is now raised instead of an :exc:`AttributeError` in
:meth:`contextlib.ExitStack.enter_context` and
:meth:`contextlib.AsyncExitStack.enter_async_context` for objects which do not
support the :term:`context manager` or :term:`asynchronous context manager`
protocols correspondingly.
(Contributed by Serhiy Storchaka in :issue:`44471`.)
* Asynchronous :ref:`comprehensions <comprehensions>` are now allowed
inside comprehensions in :ref:`asynchronous functions <async def>`.
Outer comprehensions implicitly become asynchronous in this case.
(Contributed by Serhiy Storchaka in :issue:`33346`.)

* A :exc:`TypeError` is now raised instead of an :exc:`AttributeError` in
:keyword:`with` and :keyword:`async with` statements for objects which do not
support the :term:`context manager` or :term:`asynchronous context manager`
protocols correspondingly.
(Contributed by Serhiy Storchaka in :issue:`12022`.)

* Added :meth:`object.__getstate__` which provides the default
implementation of the ``__getstate__()`` method. :mod:`Copying <copy>`
and :mod:`pickling <pickle>` instances of subclasses of builtin types
:keyword:`with` statements and :meth:`contextlib.ExitStack.enter_context`
for objects that do not support the :term:`context manager` protocol,
and in :keyword:`async with` statements and
:meth:`contextlib.AsyncExitStack.enter_async_context`
for objects not supporting the :term:`asynchronous context manager` protocol.
(Contributed by Serhiy Storchaka in :issue:`12022` and :issue:`44471`.)

* Added :meth:`object.__getstate__`, which provides the default
implementation of the :meth:`!__getstate__` method. :mod:`copy`\ing
and :mod:`pickle`\ing instances of subclasses of builtin types
:class:`bytearray`, :class:`set`, :class:`frozenset`,
:class:`collections.OrderedDict`, :class:`collections.deque`,
:class:`weakref.WeakSet`, and :class:`datetime.tzinfo` now copies and
pickles instance attributes implemented as :term:`slots <__slots__>`.
(Contributed by Serhiy Storchaka in :issue:`26579`.)

* Add :option:`-P` command line option and :envvar:`PYTHONSAFEPATH` environment
variable to not prepend a potentially unsafe path to :data:`sys.path` such as
the current directory, the script's directory or an empty string.
* Added a :option:`-P` command line option
and a :envvar:`PYTHONSAFEPATH` environment variable,
which disable the automatic prepending to :data:`sys.path`
of the script's directory when running a script,
or the current directory when using :option:`-c` and :option:`-m`.
This ensures only stdlib and installed modules
are picked up by :keyword:`import`,
and avoids unintentionally or maliciously shadowing modules
with those in a local (and typically user-writable) directory.
(Contributed by Victor Stinner in :gh:`57684`.)

* A ``"z"`` option was added to the format specification mini-language that
coerces negative zero to zero after rounding to the format precision. See
:pep:`682` for more details. (Contributed by John Belmonte in :gh:`90153`.)
* A ``"z"`` option was added to the :ref:`formatspec` that
coerces negative to positive zero after rounding to the format precision.
See :pep:`682` for more details.
(Contributed by John Belmonte in :gh:`90153`.)

* Bytes are no longer accepted on :attr:`sys.path`. Support broke sometime
between Python 3.2 and 3.6 with no one noticing until after Python 3.10.0
was released. Bringing back support would also be problematic due to
interactions between :option:`-b` and :attr:`sys.path_importer_cache` when
there is a mixture of strings and bytes keys.
* Bytes are no longer accepted on :data:`sys.path`. Support broke sometime
between Python 3.2 and 3.6, with no one noticing until after Python 3.10.0
was released. In addition, bringing back support would be problematic due to
interactions between :option:`-b` and :data:`sys.path_importer_cache` when
there is a mixture of :class:`str` and :class:`bytes` keys.
(Contributed by Thomas Grainger in :gh:`91181`.)

Other CPython Implementation Changes
Expand Down