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

Clarify "Using types...but not at runtime" docs #15029

Merged
Merged
Changes from 1 commit
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
10 changes: 10 additions & 0 deletions docs/source/runtime_troubles.rst
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,20 @@ sections, these can be dealt with by using :ref:`typing.TYPE_CHECKING

.. code-block:: python

from __future__ import annotations
from typing import TYPE_CHECKING
if TYPE_CHECKING:
from _typeshed import SupportsRichComparison

def f(x: SupportsRichComparison) -> None

Note that the ``from __future__ import annotations`` is required to avoid
a ``NameError`` at the use site of the excluded import. In the example above,
``def f(x: SupportsRichComparison)`` would raise ``NameError`` if
``from __future__ import annotations`` is not included. For more information,
and additional caveats, see the section on
:ref:`future annotations <future-annotations>`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Note that the ``from __future__ import annotations`` is required to avoid
a ``NameError`` at the use site of the excluded import. In the example above,
``def f(x: SupportsRichComparison)`` would raise ``NameError`` if
``from __future__ import annotations`` is not included. For more information,
and additional caveats, see the section on
:ref:`future annotations <future-annotations>`.
The ``from __future__ import annotations`` is required to avoid
a ``NameError`` when using the imported symbol.
For more information and caveats, see the section on
:ref:`future annotations <future-annotations>`.


.. _generic-builtins:

Using generic builtins
Expand Down