Skip to content

Commit 837c120

Browse files
miss-islingtonCAM-Gerlach
authored andcommitted
gh-95913: Copyedit, link & format Typing Features section in 3.11 What's New (GH-96097)
Co-authored-by: Ezio Melotti <[email protected]> Co-authored-by: Alex Waygood <[email protected]> (cherry picked from commit 558768f) Co-authored-by: C.A.M. Gerlach <[email protected]>
1 parent 2a1e9b0 commit 837c120

File tree

1 file changed

+50
-23
lines changed

1 file changed

+50
-23
lines changed

Doc/whatsnew/3.11.rst

+50-23
Original file line numberDiff line numberDiff line change
@@ -231,22 +231,28 @@ All releases of Python since 3.5 have included this in their 32-bit builds.
231231

232232

233233
.. _new-feat-related-type-hints-311:
234+
.. _whatsnew311-typing-features:
234235

235236
New Features Related to Type Hints
236237
==================================
237238

238239
This section covers major changes affecting :pep:`484` type hints and
239240
the :mod:`typing` module.
240241

242+
243+
.. _whatsnew311-pep646:
244+
241245
PEP 646: Variadic generics
242246
--------------------------
243247

244-
:pep:`484` introduced :data:`~typing.TypeVar`, enabling creation
245-
of generics parameterised with a single type. :pep:`646` introduces
248+
:pep:`484` previously introduced :data:`~typing.TypeVar`, enabling creation
249+
of generics parameterised with a single type. :pep:`646` adds
246250
:data:`~typing.TypeVarTuple`, enabling parameterisation
247251
with an *arbitrary* number of types. In other words,
248252
a :data:`~typing.TypeVarTuple` is a *variadic* type variable,
249-
enabling *variadic* generics. This enables a wide variety of use cases.
253+
enabling *variadic* generics.
254+
255+
This enables a wide variety of use cases.
250256
In particular, it allows the type of array-like structures
251257
in numerical computing libraries such as NumPy and TensorFlow to be
252258
parameterised with the array *shape*. Static type checkers will now
@@ -258,26 +264,30 @@ See :pep:`646` for more details.
258264
Serhiy Storchaka and Jelle Zijlstra. PEP written by Mark Mendoza, Matthew
259265
Rahtz, Pradeep Kumar Srinivasan, and Vincent Siles.)
260266

267+
268+
.. _whatsnew311-pep655:
269+
261270
PEP 655: Marking individual ``TypedDict`` items as required or not-required
262271
---------------------------------------------------------------------------
263272

264273
:data:`~typing.Required` and :data:`~typing.NotRequired` provide a
265274
straightforward way to mark whether individual items in a
266-
:data:`~typing.TypedDict` must be present. Previously this was only possible
275+
:class:`~typing.TypedDict` must be present. Previously, this was only possible
267276
using inheritance.
268277

269-
Fields are still required by default, unless the ``total=False``
270-
parameter is set.
271-
For example, the following specifies a dictionary with one required and
272-
one not-required key::
278+
All fields are still required by default,
279+
unless the *total* parameter is set to ``False``,
280+
in which case all fields are still not-required by default.
281+
For example, the following specifies a :class:`!TypedDict`
282+
with one required and one not-required key::
273283

274284
class Movie(TypedDict):
275285
title: str
276286
year: NotRequired[int]
277287

278-
m1: Movie = {"title": "Black Panther", "year": 2018} # ok
279-
m2: Movie = {"title": "Star Wars"} # ok (year is not required)
280-
m3: Movie = {"year": 2022} # error (missing required field title)
288+
m1: Movie = {"title": "Black Panther", "year": 2018} # OK
289+
m2: Movie = {"title": "Star Wars"} # OK (year is not required)
290+
m3: Movie = {"year": 2022} # ERROR (missing required field title)
281291

282292
The following definition is equivalent::
283293

@@ -290,15 +300,20 @@ See :pep:`655` for more details.
290300
(Contributed by David Foster and Jelle Zijlstra in :issue:`47087`. PEP
291301
written by David Foster.)
292302

303+
304+
.. _whatsnew311-pep673:
305+
293306
PEP 673: ``Self`` type
294307
----------------------
295308

296309
The new :data:`~typing.Self` annotation provides a simple and intuitive
297310
way to annotate methods that return an instance of their class. This
298-
behaves the same as the :data:`~typing.TypeVar`-based approach specified
299-
in :pep:`484` but is more concise and easier to follow.
311+
behaves the same as the :class:`~typing.TypeVar`-based approach
312+
:pep:`specified in PEP 484 <484#annotating-instance-and-class-methods>`,
313+
but is more concise and easier to follow.
300314

301-
Common use cases include alternative constructors provided as classmethods
315+
Common use cases include alternative constructors provided as
316+
:func:`classmethod <classmethod>`\s,
302317
and :meth:`~object.__enter__` methods that return ``self``::
303318

304319
class MyLock:
@@ -323,6 +338,9 @@ See :pep:`673` for more details.
323338
(Contributed by James Hilton-Balfe in :issue:`46534`. PEP written by
324339
Pradeep Kumar Srinivasan and James Hilton-Balfe.)
325340

341+
342+
.. _whatsnew311-pep675:
343+
326344
PEP 675: Arbitrary literal string type
327345
--------------------------------------
328346

@@ -357,14 +375,17 @@ See :pep:`675` for more details.
357375
(Contributed by Jelle Zijlstra in :issue:`47088`. PEP written by Pradeep
358376
Kumar Srinivasan and Graham Bleaney.)
359377

378+
379+
.. _whatsnew311-pep681:
380+
360381
PEP 681: Data Class Transforms
361382
------------------------------
362383

363384
:data:`~typing.dataclass_transform` may be used to
364385
decorate a class, metaclass, or a function that is itself a decorator.
365386
The presence of ``@dataclass_transform()`` tells a static type checker that the
366-
decorated object performs runtime "magic" that
367-
transforms a class, giving it :func:`dataclasses.dataclass`-like behaviors.
387+
decorated object performs runtime "magic" that transforms a class,
388+
giving it :func:`dataclass <dataclasses.dataclass>`-like behaviors.
368389

369390
For example::
370391

@@ -376,26 +397,32 @@ For example::
376397
cls.__ne__ = ...
377398
return cls
378399

379-
# The create_model decorator can now be used to create new model
380-
# classes, like this:
400+
# The create_model decorator can now be used to create new model classes:
381401
@create_model
382402
class CustomerModel:
383403
id: int
384404
name: str
385405

386-
c = CustomerModel(id=327, name="John Smith")
406+
c = CustomerModel(id=327, name="Eric Idle")
387407

388408
See :pep:`681` for more details.
389409

390410
(Contributed by Jelle Zijlstra in :gh:`91860`. PEP written by
391411
Erik De Bonte and Eric Traut.)
392412

393-
PEP 563 May Not Be the Future
413+
414+
.. _whatsnew311-pep563-deferred:
415+
416+
PEP 563 may not be the future
394417
-----------------------------
395418

396-
* :pep:`563` Postponed Evaluation of Annotations, ``__future__.annotations``
397-
that was planned for this release has been indefinitely postponed.
398-
See `this message <https://mail.python.org/archives/list/[email protected]/message/VIZEBX5EYMSYIJNDBF6DMUMZOCWHARSO/>`_ for more information.
419+
:pep:`563` Postponed Evaluation of Annotations
420+
(the ``from __future__ import annotations`` :ref:`future statement <future>`)
421+
that was originally planned for release in Python 3.10
422+
has been put on hold indefinitely.
423+
See `this message from the Steering Council <https://mail.python.org/archives/list/[email protected]/message/VIZEBX5EYMSYIJNDBF6DMUMZOCWHARSO/>`__
424+
for more information.
425+
399426

400427
Other Language Changes
401428
======================

0 commit comments

Comments
 (0)