From ab86a0718cf61414930dfabeae0e467eb34c5116 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 25 Apr 2023 18:00:49 +0200 Subject: [PATCH 1/3] Remove deprecated is_sys_guard + is_typing_guard methods --- ChangeLog | 4 +++ astroid/nodes/node_classes.py | 54 ----------------------------------- 2 files changed, 4 insertions(+), 54 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78e65f4b78..3f14a9b0cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -121,6 +121,10 @@ Release date: TBA Refs #2141 +* Remove deprecated ``If.is_sys_guard`` and ``If.is_typing_guard`` methods. + + Refs #2153 + What's New in astroid 2.15.5? ============================= diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index d6833a310f..3c63312a7c 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -9,7 +9,6 @@ import abc import itertools import typing -import warnings from collections.abc import Generator, Iterable, Iterator, Mapping from functools import cached_property, lru_cache from typing import ( @@ -2503,59 +2502,6 @@ def _get_yield_nodes_skip_lambdas(self): yield from self.test._get_yield_nodes_skip_lambdas() yield from super()._get_yield_nodes_skip_lambdas() - def is_sys_guard(self) -> bool: - """Return True if IF stmt is a sys.version_info guard. - - >>> import astroid - >>> node = astroid.extract_node(''' - import sys - if sys.version_info > (3, 8): - from typing import Literal - else: - from typing_extensions import Literal - ''') - >>> node.is_sys_guard() - True - """ - warnings.warn( - "The 'is_sys_guard' function is deprecated and will be removed in astroid 3.0.0 " - "It has been moved to pylint and can be imported from 'pylint.checkers.utils' " - "starting with pylint 2.12", - DeprecationWarning, - stacklevel=2, - ) - if isinstance(self.test, Compare): - value = self.test.left - if isinstance(value, Subscript): - value = value.value - if isinstance(value, Attribute) and value.as_string() == "sys.version_info": - return True - - return False - - def is_typing_guard(self) -> bool: - """Return True if IF stmt is a typing guard. - - >>> import astroid - >>> node = astroid.extract_node(''' - from typing import TYPE_CHECKING - if TYPE_CHECKING: - from xyz import a - ''') - >>> node.is_typing_guard() - True - """ - warnings.warn( - "The 'is_typing_guard' function is deprecated and will be removed in astroid 3.0.0 " - "It has been moved to pylint and can be imported from 'pylint.checkers.utils' " - "starting with pylint 2.12", - DeprecationWarning, - stacklevel=2, - ) - return isinstance( - self.test, (Name, Attribute) - ) and self.test.as_string().endswith("TYPE_CHECKING") - class IfExp(NodeNG): """Class representing an :class:`ast.IfExp` node. From b45f2f4e5cdce0e2058106f244ff01d207ce711c Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 25 Apr 2023 18:18:28 +0200 Subject: [PATCH 2/3] Fix tests --- tests/test_nodes.py | 60 --------------------------------------------- 1 file changed, 60 deletions(-) diff --git a/tests/test_nodes.py b/tests/test_nodes.py index 1d8d67a049..aabd26119e 100644 --- a/tests/test_nodes.py +++ b/tests/test_nodes.py @@ -338,66 +338,6 @@ def test_block_range(self) -> None: self.assertEqual(self.astroid.body[1].orelse[0].block_range(7), (7, 8)) self.assertEqual(self.astroid.body[1].orelse[0].block_range(8), (8, 8)) - @staticmethod - @pytest.mark.filterwarnings("ignore:.*is_sys_guard:DeprecationWarning") - def test_if_sys_guard() -> None: - code = builder.extract_node( - """ - import sys - if sys.version_info > (3, 8): #@ - pass - - if sys.version_info[:2] > (3, 8): #@ - pass - - if sys.some_other_function > (3, 8): #@ - pass - """ - ) - assert isinstance(code, list) and len(code) == 3 - - assert isinstance(code[0], nodes.If) - assert code[0].is_sys_guard() is True - assert isinstance(code[1], nodes.If) - assert code[1].is_sys_guard() is True - - assert isinstance(code[2], nodes.If) - assert code[2].is_sys_guard() is False - - @staticmethod - @pytest.mark.filterwarnings("ignore:.*is_typing_guard:DeprecationWarning") - def test_if_typing_guard() -> None: - code = builder.extract_node( - """ - import typing - import typing as t - from typing import TYPE_CHECKING - - if typing.TYPE_CHECKING: #@ - pass - - if t.TYPE_CHECKING: #@ - pass - - if TYPE_CHECKING: #@ - pass - - if typing.SOME_OTHER_CONST: #@ - pass - """ - ) - assert isinstance(code, list) and len(code) == 4 - - assert isinstance(code[0], nodes.If) - assert code[0].is_typing_guard() is True - assert isinstance(code[1], nodes.If) - assert code[1].is_typing_guard() is True - assert isinstance(code[2], nodes.If) - assert code[2].is_typing_guard() is True - - assert isinstance(code[3], nodes.If) - assert code[3].is_typing_guard() is False - class TryExceptNodeTest(_NodeTest): CODE = """ From 010edcc3bbbd74ba9af176af947f3dc13077ea22 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Tue, 25 Apr 2023 18:50:00 +0200 Subject: [PATCH 3/3] Update ChangeLog Co-authored-by: Pierre Sassoulas --- ChangeLog | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 3f14a9b0cf..baa2a493eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -121,7 +121,7 @@ Release date: TBA Refs #2141 -* Remove deprecated ``If.is_sys_guard`` and ``If.is_typing_guard`` methods. +* Remove deprecated ``is_sys_guard`` and ``is_typing_guard`` methods. Refs #2153