From 395bfbd670a6bf3fa043f5e7b509b9df5b83a714 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Wed, 6 Oct 2021 21:38:34 +0200 Subject: [PATCH] Deprecate ``is_typing_guard`` and ``is_sys_guard`` (#1202) * Deprecate is_typing_guard and is_sys_guard References #1199 Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> --- ChangeLog | 5 +++++ astroid/nodes/node_classes.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/ChangeLog b/ChangeLog index 0b55c004f5..5e6f1522c8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -40,6 +40,11 @@ Release date: TBA Closes PyCQA/pylint#5059 +* The ``is_typing_guard`` and ``is_sys_guard`` functions are deprecated and will + be removed in 3.0.0. They are complex meta-inference functions that are better + suited for pylint. Import them from ``pylint.checkers.utils`` instead + (requires pylint ``2.12``). + What's New in astroid 2.8.0? ============================ diff --git a/astroid/nodes/node_classes.py b/astroid/nodes/node_classes.py index c54f82e283..d59db37c6c 100644 --- a/astroid/nodes/node_classes.py +++ b/astroid/nodes/node_classes.py @@ -39,6 +39,7 @@ import itertools import sys import typing +import warnings from functools import lru_cache from typing import TYPE_CHECKING, Callable, Generator, Optional @@ -2870,6 +2871,10 @@ def is_sys_guard(self) -> bool: >>> node.is_sys_guard() True """ + warnings.warn( + "The 'is_sys_guard' function is deprecated and will be removed in astroid 3.0.0", + DeprecationWarning, + ) if isinstance(self.test, Compare): value = self.test.left if isinstance(value, Subscript): @@ -2891,6 +2896,10 @@ def is_typing_guard(self) -> bool: >>> node.is_typing_guard() True """ + warnings.warn( + "The 'is_typing_guard' function is deprecated and will be removed in astroid 3.0.0", + DeprecationWarning, + ) return isinstance( self.test, (Name, Attribute) ) and self.test.as_string().endswith("TYPE_CHECKING")