From 76d6fe95eb7af8bd4b906fc680a7b840a351ca02 Mon Sep 17 00:00:00 2001 From: Andrew Choi Date: Thu, 19 Sep 2024 10:18:54 -0700 Subject: [PATCH] Do not use IAstroidChecker for pylint versions >= 2.5.0 (#1704) --- tools/codestyle/docstring_checker.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/tools/codestyle/docstring_checker.py b/tools/codestyle/docstring_checker.py index 93aab4357..a2e6f35ce 100644 --- a/tools/codestyle/docstring_checker.py +++ b/tools/codestyle/docstring_checker.py @@ -13,11 +13,16 @@ # limitations under the License. """DocstringChecker is used to check python doc string's style.""" -import six import astroid -from pylint.checkers import BaseChecker, utils -from pylint.interfaces import IAstroidChecker +from pylint.checkers import BaseChecker +# Newer versions of pylint (>= 2.5.0) do not have IAstroidChecker +try: + from pylint.interfaces import IAstroidChecker + + IASTROID_CHECKER_AVAILABLE = True +except ImportError: + IASTROID_CHECKER_AVAILABLE = False from collections import defaultdict import re @@ -112,7 +117,8 @@ class DocstringChecker(BaseChecker): """DosstringChecker is pylint checker to check docstring style. """ - __implements__ = (IAstroidChecker, ) + if IASTROID_CHECKER_AVAILABLE: + __implements__ = (IAstroidChecker, ) POSITIONAL_MESSAGE_ID = 'str-used-on-positional-format-argument' KEYWORD_MESSAGE_ID = 'str-used-on-keyword-format-argument'