classification
Title: Change typing.TYPE_CHECKING doc example
Type: behavior Stage: resolved
Components: Documentation Versions: Python 3.7, Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Jelle Zijlstra, berker.peksag, docs@python, levkivskyi, rav
Priority: normal Keywords:

Created on 2017-04-03 17:32 by rav, last changed 2017-04-26 15:21 by levkivskyi. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 982 merged rav, 2017-04-03 17:33
PR 1297 merged berker.peksag, 2017-04-26 13:31
PR 1299 merged berker.peksag, 2017-04-26 13:34
Messages (11)
msg291085 - (view) Author: Mathias Rav (rav) * Date: 2017-04-03 17:32
The documentation of typing.TYPE_CHECKING has an example (introduced in issue #26141) that would lead to NameError at runtime. The example shows how to limit the import of "expensive_mod" to type checkers, but then goes on to use "expensive_mod.some_type" in a type annotation that is evaluated at runtime ("local_var: expensive_mod.some_type"). The use case of TYPE_CHECKING is probably meant for type annotations placed in comments, e.g. "local_var  # type: expensive_mod.some_type".
msg291101 - (view) Author: Jelle Zijlstra (Jelle Zijlstra) * (Python triager) Date: 2017-04-04 04:56
The example is actually correct; I just confirmed by running it in my shell. Type annotations on local variables are not evaluated at runtime; see PEP 526.
msg291121 - (view) Author: Mathias Rav (rav) * Date: 2017-04-04 12:13
I have updated the patch after feedback from Jelle Zijlstra and Ivan Levkevskyi. Indeed the example was correct; the patch now adds wording from PEP 484 and PEP 526 to clarify why a function parameter annotation needs to be in quotes and a local variable annotation does not.
msg292332 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-04-26 10:49
New changeset 87c07fe9d908d0a2143fcc8369255c6ff3241503 by Berker Peksag (Mathias Rav) in branch 'master':
bpo-29974: Improve typing.TYPE_CHECKING example (GH-982)
https://github.com/python/cpython/commit/87c07fe9d908d0a2143fcc8369255c6ff3241503
msg292334 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-04-26 11:32
87c07fe9d908d0a2143fcc8369255c6ff3241503 should still be backported to 3.5 and 3.6 branches so please don't close it yet.
msg292351 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2017-04-26 14:23
> 87c07fe9d908d0a2143fcc8369255c6ff3241503 should still be backported to 3.5 and 3.6 branches so please don't close it yet.

Thanks for making backport PRs! (and sorry for closing prematurely)
msg292352 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-04-26 14:24
New changeset 271a289a03ad10c91c5326bde3020f1cdf6a1fff by Berker Peksag in branch '3.5':
bpo-29974: Improve typing.TYPE_CHECKING example (GH-982)
https://github.com/python/cpython/commit/271a289a03ad10c91c5326bde3020f1cdf6a1fff
msg292353 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-04-26 14:25
New changeset 04f389b8b357c8507b6c9642adcb8b956489e034 by Berker Peksag in branch '3.6':
bpo-29974: Improve typing.TYPE_CHECKING example (GH-982)
https://github.com/python/cpython/commit/04f389b8b357c8507b6c9642adcb8b956489e034
msg292354 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2017-04-26 14:28
Now all backport PRs have been merged. Thanks for the PR, Mathias.

> Thanks for making backport PRs! (and sorry for closing prematurely)

No problem, thanks for the reviews! By the way, sorry I missed the typo in your last name while doing the initial merge.
msg292361 - (view) Author: Mathias Rav (rav) * Date: 2017-04-26 15:18
Sorry for making a typo in your last name, Ivan Levkivskyi! I should know better and use copy-and-paste.
msg292362 - (view) Author: Ivan Levkivskyi (levkivskyi) * (Python committer) Date: 2017-04-26 15:21
> Sorry for making a typo in your last name

No problem!
This actually happened maaany times with me :-)
History
Date User Action Args
2017-04-26 15:21:38levkivskyisetmessages: + msg292362
2017-04-26 15:18:35ravsetmessages: + msg292361
2017-04-26 14:28:41berker.peksagsetstatus: open -> closed
resolution: fixed
messages: + msg292354

stage: backport needed -> resolved
2017-04-26 14:25:39berker.peksagsetmessages: + msg292353
2017-04-26 14:24:38berker.peksagsetmessages: + msg292352
2017-04-26 14:23:52levkivskyisetmessages: + msg292351
2017-04-26 13:34:24berker.peksagsetpull_requests: + pull_request1406
2017-04-26 13:31:53berker.peksagsetpull_requests: + pull_request1404
2017-04-26 11:32:48berker.peksagsetstatus: closed -> open
resolution: fixed -> (no value)
messages: + msg292334

stage: resolved -> backport needed
2017-04-26 11:06:53levkivskyisetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-04-26 10:49:49berker.peksagsetnosy: + berker.peksag
messages: + msg292332
2017-04-07 17:50:07levkivskyisetnosy: + levkivskyi
2017-04-04 12:13:36ravsetmessages: + msg291121
2017-04-04 12:11:01ravsettitle: typing.TYPE_CHECKING doc example is incorrect -> Change typing.TYPE_CHECKING doc example
2017-04-04 04:56:37Jelle Zijlstrasetnosy: + Jelle Zijlstra
messages: + msg291101
2017-04-04 01:36:23berker.peksagsetstage: patch review
type: enhancement -> behavior
versions: - Python 3.4
2017-04-03 17:33:16ravsetpull_requests: + pull_request1155
2017-04-03 17:32:43ravcreate