Skip to content

Commit b7c326f

Browse files
authored
[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
1 parent c046906 commit b7c326f

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

tools/pylint-extensions/pylint-guidelines-checker/pylint_guidelines_checker.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -890,17 +890,17 @@ def visit_return(self, node):
890890
paging_class = False
891891

892892
try:
893-
if "def by_page" in next(node.value.infer()).as_string():
893+
if any(v for v in node.value.infer() if "def by_page" in v.as_string()):
894894
paging_class = True
895-
except (astroid.exceptions.InferenceError, AttributeError): # astroid can't always infer the return
895+
except (astroid.exceptions.InferenceError, AttributeError, TypeError): # astroid can't always infer the return
896896
logger.debug("Pylint custom checker failed to check if client list method uses core paging.")
897-
pass
897+
return
898898

899899
if not paging_class:
900900
self.add_message(
901901
msgid="client-list-methods-use-paging", node=node.parent, confidence=None
902902
)
903-
except AttributeError:
903+
except (AttributeError, TypeError):
904904
logger.debug("Pylint custom checker failed to check if client list method uses core paging.")
905905
pass
906906

tools/pylint-extensions/pylint-guidelines-checker/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name="pylint-guidelines-checker",
5-
version="0.0.6",
5+
version="0.0.7",
66
url='http://github.com/Azure/azure-sdk-for-python',
77
license='MIT License',
88
description="A pylint plugin which enforces azure sdk guidelines.",

tools/pylint-extensions/pylint-guidelines-checker/tests/test_pylint_custom_plugins.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1944,21 +1944,21 @@ def list_thing2(self): #@
19441944
def test_finds_method_returning_something_else_async(self):
19451945
class_node, function_node_a, function_node_b = astroid.extract_node("""
19461946
from azure.core.polling import LROPoller
1947+
from typing import list
19471948
19481949
class SomeClient(): #@
19491950
async def list_thing(self, **kwargs): #@
19501951
return list()
19511952
async def list_thing2(self, **kwargs): #@
1952-
from azure.core.polling import LROPoller
19531953
return LROPoller()
19541954
""")
19551955

19561956
with self.assertAddsMessages(
19571957
pylint.testutils.MessageTest(
1958-
msg_id="client-list-methods-use-paging", line=5, node=function_node_a, col_offset=4, end_line=5, end_col_offset=24
1958+
msg_id="client-list-methods-use-paging", line=6, node=function_node_a, col_offset=4, end_line=6, end_col_offset=24
19591959
),
19601960
pylint.testutils.MessageTest(
1961-
msg_id="client-list-methods-use-paging", line=7, node=function_node_b, col_offset=4, end_line=7, end_col_offset=25
1961+
msg_id="client-list-methods-use-paging", line=8, node=function_node_b, col_offset=4, end_line=8, end_col_offset=25
19621962
),
19631963
):
19641964
self.checker.visit_return(function_node_a.body[0])
@@ -2592,7 +2592,7 @@ async def function_foo(x, y, z):
25922592
This is Example content.
25932593
Should support multi-line.
25942594
Can also include file:
2595-
2595+
25962596
.. literalinclude:: ../samples/sample_detect_language.py
25972597
'''
25982598
"""

0 commit comments

Comments
 (0)