Skip to content

Commit 77b4120

Browse files
committed
Update Modernizing document for Python 3.14
Document that the future import isn't necessary anymore.
1 parent 5d0e6f8 commit 77b4120

File tree

1 file changed

+27
-6
lines changed

1 file changed

+27
-6
lines changed

docs/guides/modernizing.rst

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ but they are superseded by more modern alternatives, which are recommended to us
1919
These newer features are not available in all Python versions, although
2020
some features are available as backports from the
2121
`typing-extensions <https://pypi.org/project/typing-extensions/>`_
22-
package, or require quoting or using :python:`from __future__ import annotations`.
22+
package, or require quoting or using :python:`from __future__ import annotations`
23+
when running on Python 3.13 or below.
2324
Each section states the minimum Python version required to use the
2425
feature, whether it is available in typing-extensions, and whether it is
2526
available using quoting.
@@ -39,16 +40,18 @@ available using quoting.
3940

4041
.. note::
4142

42-
:python:`from __future__ import annotations` is available since Python 3.7.
43+
:python:`from __future__ import annotations` is available since Python 3.7
44+
and became unnecessary starting with Python 3.14.
4345
This only has an effect inside type annotations, while quoting is still
44-
required outside. For example, this example runs on Python 3.7 and up,
45-
although the pipe operator was only introduced in Python 3.10::
46+
required outside. For example::
4647

4748
from __future__ import annotations
4849
from typing_extensions import TypeAlias
4950

50-
def f(x: int | None) -> int | str: ... # the future import is sufficient
51-
Alias: TypeAlias = "int | str" # this requires quoting
51+
def f(x: Foo) -> Foo: ... # the future import is sufficient
52+
Alias: TypeAlias = "Foo" # this forward reference requires quoting
53+
54+
class Foo: pass
5255

5356
.. _modernizing-type-comments:
5457

@@ -82,6 +85,9 @@ it's necessary to either use :python:`from __future__ import annotations`
8285

8386
class Parrot: ...
8487

88+
When using Python 3.14 and up, quoting forward references is no longer
89+
necessary inside type annotations.
90+
8591
.. _modernizing-typing-text:
8692

8793
``typing.Text``
@@ -354,3 +360,18 @@ behavior, but has other restrictions. See the documentation for
354360

355361
Review existing uses of :data:`TypeGuard <typing.TypeGuard>` to see if they
356362
should be replaced with :data:`TypeIs <typing.TypeIs>`.
363+
364+
``from __future__ import annotations``
365+
======================================
366+
367+
*Available since:* Python 3.14
368+
369+
Starting with Python 3.14, behavior similar to using
370+
``from __future__ import annotations`` became the default. When running on
371+
Python 3.14 and up, it's no longer necessary to use the future import to defer
372+
evaluation of annotations. However, quoting is still necessary for types used
373+
outside of annotations and :keyword:`type` statements, for example when using
374+
:data:`TypeAlias <typing.TypeAlias>`.
375+
376+
Remove unnecessary uses of ``from __future__ import annotations`` for code
377+
only supporting Python 3.14 and up.

0 commit comments

Comments
 (0)