Method: pylint.checkers.utils.is_typing_guard
Calls: 129, Exceptions: 0, Paths: 2Back
Path 1: 98 calls (0.76)
If (98)
True (74) False (24)
1def is_typing_guard(node: nodes.If) -> bool:
2 """Return True if IF stmt is a typing guard.
3
4 >>> from typing import TYPE_CHECKING
5 >>> if TYPE_CHECKING:
6 >>> from xyz import a
7 """
8 return isinstance(
9 node.test, (nodes.Name, nodes.Attribute)
10 ) and node.test.as_string().endswith("TYPE_CHECKING")
Path 2: 31 calls (0.24)
If (31)
False (31)
1def is_typing_guard(node: nodes.If) -> bool:
2 """Return True if IF stmt is a typing guard.
3
4 >>> from typing import TYPE_CHECKING
5 >>> if TYPE_CHECKING:
6 >>> from xyz import a
7 """
8 return isinstance(
9 node.test, (nodes.Name, nodes.Attribute)
10 ) and node.test.as_string().endswith("TYPE_CHECKING")