[Pylint] adding in TypeError to exception for next() if type cant be inferred (#3843)

* adding in TypeError to exception for next() if type cant be inferred

* update version

* fix paging test

* pass -> return so that on exceptions we dont throw a warning

* fixing merge conflict

* spacing:

* spacing
This commit is contained in:
Libba Lawrence 2022-08-05 10:56:29 -07:00 коммит произвёл GitHub
Родитель c0469066dd
Коммит b7c326fac0
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
3 изменённых файлов: 9 добавлений и 9 удалений

Просмотреть файл

@ -890,17 +890,17 @@ class ClientListMethodsUseCorePaging(BaseChecker):
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

Просмотреть файл

@ -2,7 +2,7 @@ from setuptools import setup
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.",

Просмотреть файл

@ -1944,21 +1944,21 @@ class TestClientListMethodsUseCorePaging(pylint.testutils.CheckerTestCase):
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 @@ class TestCheckDocstringAdmonitionNewline(pylint.testutils.CheckerTestCase):
This is Example content.
Should support multi-line.
Can also include file:
.. literalinclude:: ../samples/sample_detect_language.py
'''
"""