Skip to content

Commit 1ec230f

Browse files
committed
bpo-29974: Change typing.TYPE_CHECKING doc example
* Fix PEP 8 (SomeType instead of some_type) * Add a function parameter annotation * Explain, using wording from PEP 484 and PEP 526, why one annotation is in quotes and another is not. Suggested by Ivan Levkevskyi.
1 parent cf1958a commit 1ec230f

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

Doc/library/typing.rst

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,5 +1005,10 @@ The module defines the following classes, functions and decorators:
10051005
if TYPE_CHECKING:
10061006
import expensive_mod
10071007

1008-
def fun():
1009-
local_var: expensive_mod.some_type = other_fun()
1008+
def fun(arg: 'expensive_mod.SomeType') -> None:
1009+
local_var: expensive_mod.AnotherType = other_fun()
1010+
1011+
Note that the first type annotation must be enclosed in quotes, making it a
1012+
"forward reference", to hide the ``expensive_mod`` reference from the
1013+
interpreter runtime. Type annotations for local variables are not
1014+
evaluated, so the second annotation does not need to be enclosed in quotes.

0 commit comments

Comments
 (0)