Skip to content

Commit 08ed413

Browse files
cdce8pPierre-SassoulasDanielNoord
authored
Remove deprecated is_sys_guard + is_typing_guard (#2153)
Co-authored-by: Pierre Sassoulas <[email protected]> Co-authored-by: Daniël van Noord <[email protected]>
1 parent 6865b2b commit 08ed413

File tree

3 files changed

+4
-114
lines changed

3 files changed

+4
-114
lines changed

ChangeLog

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,10 @@ Release date: TBA
121121

122122
Refs #2141
123123

124+
* Remove deprecated ``is_sys_guard`` and ``is_typing_guard`` methods.
125+
126+
Refs #2153
127+
124128
* Remove deprecated ``Ellipsis``, ``ExtSlice``, ``Index`` nodes.
125129

126130
Refs #2152

astroid/nodes/node_classes.py

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import abc
1010
import itertools
1111
import typing
12-
import warnings
1312
from collections.abc import Generator, Iterable, Iterator, Mapping
1413
from functools import cached_property, lru_cache
1514
from typing import (
@@ -2483,59 +2482,6 @@ def _get_yield_nodes_skip_lambdas(self):
24832482
yield from self.test._get_yield_nodes_skip_lambdas()
24842483
yield from super()._get_yield_nodes_skip_lambdas()
24852484

2486-
def is_sys_guard(self) -> bool:
2487-
"""Return True if IF stmt is a sys.version_info guard.
2488-
2489-
>>> import astroid
2490-
>>> node = astroid.extract_node('''
2491-
import sys
2492-
if sys.version_info > (3, 8):
2493-
from typing import Literal
2494-
else:
2495-
from typing_extensions import Literal
2496-
''')
2497-
>>> node.is_sys_guard()
2498-
True
2499-
"""
2500-
warnings.warn(
2501-
"The 'is_sys_guard' function is deprecated and will be removed in astroid 3.0.0 "
2502-
"It has been moved to pylint and can be imported from 'pylint.checkers.utils' "
2503-
"starting with pylint 2.12",
2504-
DeprecationWarning,
2505-
stacklevel=2,
2506-
)
2507-
if isinstance(self.test, Compare):
2508-
value = self.test.left
2509-
if isinstance(value, Subscript):
2510-
value = value.value
2511-
if isinstance(value, Attribute) and value.as_string() == "sys.version_info":
2512-
return True
2513-
2514-
return False
2515-
2516-
def is_typing_guard(self) -> bool:
2517-
"""Return True if IF stmt is a typing guard.
2518-
2519-
>>> import astroid
2520-
>>> node = astroid.extract_node('''
2521-
from typing import TYPE_CHECKING
2522-
if TYPE_CHECKING:
2523-
from xyz import a
2524-
''')
2525-
>>> node.is_typing_guard()
2526-
True
2527-
"""
2528-
warnings.warn(
2529-
"The 'is_typing_guard' function is deprecated and will be removed in astroid 3.0.0 "
2530-
"It has been moved to pylint and can be imported from 'pylint.checkers.utils' "
2531-
"starting with pylint 2.12",
2532-
DeprecationWarning,
2533-
stacklevel=2,
2534-
)
2535-
return isinstance(
2536-
self.test, (Name, Attribute)
2537-
) and self.test.as_string().endswith("TYPE_CHECKING")
2538-
25392485

25402486
class IfExp(NodeNG):
25412487
"""Class representing an :class:`ast.IfExp` node.

tests/test_nodes.py

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -338,66 +338,6 @@ def test_block_range(self) -> None:
338338
self.assertEqual(self.astroid.body[1].orelse[0].block_range(7), (7, 8))
339339
self.assertEqual(self.astroid.body[1].orelse[0].block_range(8), (8, 8))
340340

341-
@staticmethod
342-
@pytest.mark.filterwarnings("ignore:.*is_sys_guard:DeprecationWarning")
343-
def test_if_sys_guard() -> None:
344-
code = builder.extract_node(
345-
"""
346-
import sys
347-
if sys.version_info > (3, 8): #@
348-
pass
349-
350-
if sys.version_info[:2] > (3, 8): #@
351-
pass
352-
353-
if sys.some_other_function > (3, 8): #@
354-
pass
355-
"""
356-
)
357-
assert isinstance(code, list) and len(code) == 3
358-
359-
assert isinstance(code[0], nodes.If)
360-
assert code[0].is_sys_guard() is True
361-
assert isinstance(code[1], nodes.If)
362-
assert code[1].is_sys_guard() is True
363-
364-
assert isinstance(code[2], nodes.If)
365-
assert code[2].is_sys_guard() is False
366-
367-
@staticmethod
368-
@pytest.mark.filterwarnings("ignore:.*is_typing_guard:DeprecationWarning")
369-
def test_if_typing_guard() -> None:
370-
code = builder.extract_node(
371-
"""
372-
import typing
373-
import typing as t
374-
from typing import TYPE_CHECKING
375-
376-
if typing.TYPE_CHECKING: #@
377-
pass
378-
379-
if t.TYPE_CHECKING: #@
380-
pass
381-
382-
if TYPE_CHECKING: #@
383-
pass
384-
385-
if typing.SOME_OTHER_CONST: #@
386-
pass
387-
"""
388-
)
389-
assert isinstance(code, list) and len(code) == 4
390-
391-
assert isinstance(code[0], nodes.If)
392-
assert code[0].is_typing_guard() is True
393-
assert isinstance(code[1], nodes.If)
394-
assert code[1].is_typing_guard() is True
395-
assert isinstance(code[2], nodes.If)
396-
assert code[2].is_typing_guard() is True
397-
398-
assert isinstance(code[3], nodes.If)
399-
assert code[3].is_typing_guard() is False
400-
401341

402342
class TryExceptNodeTest(_NodeTest):
403343
CODE = """

0 commit comments

Comments
 (0)