Skip to content

Commit 5bc7167

Browse files
author
hauntsaninja
committed
more edits
1 parent 8142da0 commit 5bc7167

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

docs/source/runtime_troubles.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ String literal types
2222
--------------------
2323

2424
Type comments can't cause runtime errors because comments are not evaluated by
25-
Python. Using string literal types sidesteps the problem of annotations that
26-
would cause runtime errors in a similar way.
25+
Python. In a similar way, using string literal types sidesteps the problem of
26+
annotations that would cause runtime errors.
2727

2828
Any type can be entered as a string literal, and you can combine
2929
string-literal types with non-string-literal types freely:
@@ -151,11 +151,11 @@ before. This can lead to errors at runtime like:
151151
152152
ImportError: cannot import name 'b' from partially initialized module 'A' (most likely due to a circular import)
153153
154-
If those cycles do become a problem when running your program,
155-
there's a trick: if the import is only needed for type annotations in
156-
forward references (string literals) or comments, you can write the
157-
imports inside ``if TYPE_CHECKING:`` so that they are not executed at runtime.
158-
Example:
154+
If those cycles do become a problem when running your program, there's a trick:
155+
if the import is only needed for type annotations and you're using a) the
156+
:ref:`future annotations import<future-annotations>`, or b) string literals or type
157+
comments for the relevant annotations, you can write the imports inside ``if
158+
TYPE_CHECKING:`` so that they are not executed at runtime. Example:
159159

160160
File ``foo.py``:
161161

@@ -224,7 +224,7 @@ complicated and you need to use :ref:`typing.TYPE_CHECKING
224224
task_queue: Tasks
225225
reveal_type(task_queue.get()) # Reveals str
226226
227-
If your subclass is also generic, you can using something like the following:
227+
If your subclass is also generic, you can use the following:
228228

229229
.. code-block:: python
230230

0 commit comments

Comments
 (0)