diff --git a/tools/pylint-extensions/pylint-guidelines-checker/pylint_guidelines_checker.py b/tools/pylint-extensions/pylint-guidelines-checker/pylint_guidelines_checker.py index 20838469f0c..b372190540a 100644 --- a/tools/pylint-extensions/pylint-guidelines-checker/pylint_guidelines_checker.py +++ b/tools/pylint-extensions/pylint-guidelines-checker/pylint_guidelines_checker.py @@ -890,17 +890,17 @@ def visit_return(self, node): paging_class = False try: - if "def by_page" in next(node.value.infer()).as_string(): + if any(v for v in node.value.infer() if "def by_page" in v.as_string()): paging_class = True - except (astroid.exceptions.InferenceError, AttributeError): # astroid can't always infer the return + except (astroid.exceptions.InferenceError, AttributeError, TypeError): # astroid can't always infer the return logger.debug("Pylint custom checker failed to check if client list method uses core paging.") - pass + return if not paging_class: self.add_message( msgid="client-list-methods-use-paging", node=node.parent, confidence=None ) - except AttributeError: + except (AttributeError, TypeError): logger.debug("Pylint custom checker failed to check if client list method uses core paging.") pass diff --git a/tools/pylint-extensions/pylint-guidelines-checker/setup.py b/tools/pylint-extensions/pylint-guidelines-checker/setup.py index 8a471192645..1b7a8ea4487 100644 --- a/tools/pylint-extensions/pylint-guidelines-checker/setup.py +++ b/tools/pylint-extensions/pylint-guidelines-checker/setup.py @@ -2,7 +2,7 @@ setup( name="pylint-guidelines-checker", - version="0.0.6", + version="0.0.7", url='http://github.com/Azure/azure-sdk-for-python', license='MIT License', description="A pylint plugin which enforces azure sdk guidelines.", diff --git a/tools/pylint-extensions/pylint-guidelines-checker/tests/test_pylint_custom_plugins.py b/tools/pylint-extensions/pylint-guidelines-checker/tests/test_pylint_custom_plugins.py index 7fed072693c..1a4b5c691eb 100644 --- a/tools/pylint-extensions/pylint-guidelines-checker/tests/test_pylint_custom_plugins.py +++ b/tools/pylint-extensions/pylint-guidelines-checker/tests/test_pylint_custom_plugins.py @@ -1944,21 +1944,21 @@ def list_thing2(self): #@ def test_finds_method_returning_something_else_async(self): class_node, function_node_a, function_node_b = astroid.extract_node(""" from azure.core.polling import LROPoller + from typing import list class SomeClient(): #@ async def list_thing(self, **kwargs): #@ return list() async def list_thing2(self, **kwargs): #@ - from azure.core.polling import LROPoller return LROPoller() """) with self.assertAddsMessages( pylint.testutils.MessageTest( - msg_id="client-list-methods-use-paging", line=5, node=function_node_a, col_offset=4, end_line=5, end_col_offset=24 + msg_id="client-list-methods-use-paging", line=6, node=function_node_a, col_offset=4, end_line=6, end_col_offset=24 ), pylint.testutils.MessageTest( - msg_id="client-list-methods-use-paging", line=7, node=function_node_b, col_offset=4, end_line=7, end_col_offset=25 + msg_id="client-list-methods-use-paging", line=8, node=function_node_b, col_offset=4, end_line=8, end_col_offset=25 ), ): self.checker.visit_return(function_node_a.body[0]) @@ -2592,7 +2592,7 @@ async def function_foo(x, y, z): This is Example content. Should support multi-line. Can also include file: - + .. literalinclude:: ../samples/sample_detect_language.py ''' """