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
Change typing.TYPE_CHECKING doc example #74160
Comments
The documentation of typing.TYPE_CHECKING has an example (introduced in issue bpo-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". |
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. |
87c07fe 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) |
Now all backport PRs have been merged. Thanks for the PR, Mathias.
No problem, thanks for the reviews! By the way, sorry I missed the typo in your last name while doing the initial merge. |
Sorry for making a typo in your last name, Ivan Levkivskyi! I should know better and use copy-and-paste. |
No problem! |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: