Skip to content

Commit 25406f7

Browse files
[deprecation] Remove duplicated utils typing guards check (#8475)
1 parent 1f2cf71 commit 25406f7

File tree

3 files changed

+21
-60
lines changed

3 files changed

+21
-60
lines changed

doc/whatsnew/fragments/8475.internal

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Following a deprecation period, ``is_typing_guard``, ``is_node_in_typing_guarded_import_block`` and
2+
``is_node_in_guarded_import_block``: from ``pylint.utils`` were removed: use a combination of
3+
``is_sys_guard`` and ``in_type_checking_block`` instead.
4+
5+
Refs #8475

pylint/checkers/utils.py

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import numbers
1313
import re
1414
import string
15-
import warnings
1615
from collections import deque
1716
from collections.abc import Iterable, Iterator
1817
from functools import lru_cache, partial
@@ -1792,48 +1791,6 @@ def is_sys_guard(node: nodes.If) -> bool:
17921791
return False
17931792

17941793

1795-
def is_typing_guard(node: nodes.If) -> bool:
1796-
"""Return True if IF stmt is a typing guard.
1797-
1798-
>>> from typing import TYPE_CHECKING
1799-
>>> if TYPE_CHECKING:
1800-
>>> from xyz import a
1801-
"""
1802-
warnings.warn(
1803-
"This method will be removed in pylint 3.0; use in_type_checking_block() instead.",
1804-
DeprecationWarning,
1805-
stacklevel=2,
1806-
) # pragma: no cover
1807-
return isinstance(
1808-
node.test, (nodes.Name, nodes.Attribute)
1809-
) and node.test.as_string().endswith("TYPE_CHECKING")
1810-
1811-
1812-
def is_node_in_typing_guarded_import_block(node: nodes.NodeNG) -> bool:
1813-
"""Return True if node is part for guarded `typing.TYPE_CHECKING` if block."""
1814-
warnings.warn(
1815-
"This method will be removed in pylint 3.0; use in_type_checking_block() instead.",
1816-
DeprecationWarning,
1817-
stacklevel=2,
1818-
) # pragma: no cover
1819-
return isinstance(node.parent, nodes.If) and is_typing_guard(node.parent)
1820-
1821-
1822-
def is_node_in_guarded_import_block(node: nodes.NodeNG) -> bool:
1823-
"""Return True if node is part for guarded if block.
1824-
1825-
I.e. `sys.version_info` or `typing.TYPE_CHECKING`
1826-
"""
1827-
warnings.warn(
1828-
"This method will be removed in pylint 3.0; use in_type_checking_block() instead.",
1829-
DeprecationWarning,
1830-
stacklevel=2,
1831-
) # pragma: no cover
1832-
return isinstance(node.parent, nodes.If) and (
1833-
is_sys_guard(node.parent) or is_typing_guard(node.parent)
1834-
)
1835-
1836-
18371794
def is_reassigned_after_current(node: nodes.NodeNG, varname: str) -> bool:
18381795
"""Check if the given variable name is reassigned in the same scope after the
18391796
current node.

tests/checkers/unittest_utils.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -413,38 +413,37 @@ def test_if_sys_guard() -> None:
413413
assert utils.is_sys_guard(code[2]) is False
414414

415415

416-
@pytest.mark.filterwarnings("ignore::DeprecationWarning")
417416
def test_if_typing_guard() -> None:
418417
code = astroid.extract_node(
419418
"""
420419
import typing
421420
import typing as t
422421
from typing import TYPE_CHECKING
423422
424-
if typing.TYPE_CHECKING: #@
425-
pass
423+
if typing.TYPE_CHECKING:
424+
pass #@
426425
427-
if t.TYPE_CHECKING: #@
428-
pass
426+
if t.TYPE_CHECKING:
427+
pass #@
429428
430-
if TYPE_CHECKING: #@
431-
pass
429+
if TYPE_CHECKING:
430+
pass #@
432431
433-
if typing.SOME_OTHER_CONST: #@
434-
pass
432+
if typing.SOME_OTHER_CONST:
433+
pass #@
435434
"""
436435
)
437436
assert isinstance(code, list) and len(code) == 4
438437

439-
assert isinstance(code[0], nodes.If)
440-
assert utils.is_typing_guard(code[0]) is True
441-
assert isinstance(code[1], nodes.If)
442-
assert utils.is_typing_guard(code[1]) is True
443-
assert isinstance(code[2], nodes.If)
444-
assert utils.is_typing_guard(code[2]) is True
438+
assert isinstance(code[0], nodes.Pass)
439+
assert utils.in_type_checking_block(code[0]) is True
440+
assert isinstance(code[1], nodes.Pass)
441+
assert utils.in_type_checking_block(code[1]) is True
442+
assert isinstance(code[2], nodes.Pass)
443+
assert utils.in_type_checking_block(code[2]) is True
445444

446-
assert isinstance(code[3], nodes.If)
447-
assert utils.is_typing_guard(code[3]) is False
445+
assert isinstance(code[3], nodes.Pass)
446+
assert utils.in_type_checking_block(code[3]) is False
448447

449448

450449
def test_in_type_checking_block() -> None:

0 commit comments

Comments
 (0)