-
Notifications
You must be signed in to change notification settings - Fork 259
Add a constant that's False at runtime but True when type checking #230
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
Comments
There's one case where I think the if False:
from typing import ... or try:
from typing import ...
except ImportError:
... To survive the non-existence of the typing module, some idioms can't be used (especially type aliases, type variables, and generic classes) but many others are still available (especially We probably should add some language to the PEP to direct type checkers to support at least one of these (which would then become the preferred way). Currently I've mostly been recommending |
This would be nice to get into the 3.5.2 release if we can. Some name ideas:
Out of those I think I'd go for |
/cc @markshannon , since this came up in discussion at PyCon last week |
Here are some more ideas (with an usage example to better illustrate what it would look like):
Also, should this be okay if I don't want to use string literals in annotations:
|
IMO it really should be some kind of present tense verb to emphasize "if currently type checking". Maybe |
|
Maybe ANALYZING? Or would the Brits and Aussies get mad at us?
I do like TYPE_CHECKING, and at least for IDEs that seems a fine usage. It
also feels intuitive so we won't have to explain it to most people who see
it for the first time.
|
We could generali(s|z)e |
@matthiaskramm any objection to TYPE_CHECKING? --Guido (mobile)
|
I'm happy with |
OK, typing.TYPE_CHECKING it is. I'll send the changes soon.
|
This would provide a standard idiom for including imports that are only necessary while type checking, see e.g. python/mypy#1646 (which currently recommends
if False: import ...
because that's the only way to do it).The text was updated successfully, but these errors were encountered: