-
-
Notifications
You must be signed in to change notification settings - Fork 278
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
astroid.nodes.node_classes.If.is_typing_guard()
is very fragile
#1107
Comments
node_classes.If.is_typing_guard()
is very fragile
Thank you for opening the issue, you're right. |
I don't see this as an issue. Some arguments
https://docs.python.org/3/library/typing.html#typing.TYPE_CHECKING -- |
I think this is wrong question. The problem is that package/module is a namespace by itself where author should be able to define any name (except reservered dunder names) without clashing other modules/packages. This is violated currently by astroid because you cannot use
No, maybe I am not using
The docs of typing module says about |
|
node_classes.If.is_typing_guard()
is very fragilenode_classes.If.nodes.is_typing_guard()
is very fragile
node_classes.If.nodes.is_typing_guard()
is very fragileastroid.nodes.node_classes.If.is_typing_guard()
is very fragile
I just looked and
|
Steps to reproduce
Suppose project with module
bar
havingTYPE_CHECKING
constant. If any code is using this constant, astroid wrongly assumes that this part of code is part oftyping.TYPE_CHECKING
:Current behavior
Astroid assumes any constant with name
TYPE_CHECKING
is typing guard.Expected behavior
Only
TYPE_CHECKING
fromtyping
module should be considered as typing guardAdditional notes
There are more less likely code snippets that won't be correctly recognized by astroid e.g.:
if TYPE_CHECKING is True
. Astroid should try to support at least the most likely ones - e.g. sinceTYPE_CHECKING
is bool constant we should support at leastif TYPE_CHECKING is True
form.python -c "from astroid import __pkginfo__; print(__pkginfo__.version)"
outputmaster branch
The text was updated successfully, but these errors were encountered: