Skip to content

Commit

Permalink
[WIP] Deprecate redundant type checking guard utils
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Mar 11, 2023
1 parent 74e6efc commit 57202bd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions pylint/checkers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import numbers
import re
import string
import warnings
from collections import deque
from collections.abc import Iterable, Iterator
from functools import lru_cache, partial
Expand Down Expand Up @@ -1798,13 +1799,23 @@ def is_typing_guard(node: nodes.If) -> bool:
>>> if TYPE_CHECKING:
>>> from xyz import a
"""
warnings.warn(
"This method will be removed in pylint 3.0; use in_type_checking_block() instead.",
DeprecationWarning,
stacklevel=2,
)
return isinstance(
node.test, (nodes.Name, nodes.Attribute)
) and node.test.as_string().endswith("TYPE_CHECKING")


def is_node_in_typing_guarded_import_block(node: nodes.NodeNG) -> bool:
"""Return True if node is part for guarded `typing.TYPE_CHECKING` if block."""
warnings.warn(
"This method will be removed in pylint 3.0; use in_type_checking_block() instead.",
DeprecationWarning,
stacklevel=2,
)
return isinstance(node.parent, nodes.If) and is_typing_guard(node.parent)


Expand All @@ -1813,6 +1824,11 @@ def is_node_in_guarded_import_block(node: nodes.NodeNG) -> bool:
I.e. `sys.version_info` or `typing.TYPE_CHECKING`
"""
warnings.warn(
"This method will be removed in pylint 3.0; use in_type_checking_block() instead.",
DeprecationWarning,
stacklevel=2,
)
return isinstance(node.parent, nodes.If) and (
is_sys_guard(node.parent) or is_typing_guard(node.parent)
)
Expand Down

0 comments on commit 57202bd

Please sign in to comment.