Skip to content

Commit

Permalink
Deprecate is_typing_guard and is_sys_guard (#1202)
Browse files Browse the repository at this point in the history
* Deprecate is_typing_guard and is_sys_guard

References #1199

Co-authored-by: Marc Mueller <[email protected]>
  • Loading branch information
Pierre-Sassoulas and cdce8p authored Oct 6, 2021
1 parent a92487b commit 395bfbd
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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?
============================
Expand Down
9 changes: 9 additions & 0 deletions astroid/nodes/node_classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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):
Expand All @@ -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")
Expand Down

0 comments on commit 395bfbd

Please sign in to comment.