Skip to content

Commit

Permalink
[Pylint] adding in TypeError to exception for next() if type cant be …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
l0lawrence authored Aug 5, 2022
1 parent c046906 commit b7c326f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion tools/pylint-extensions/pylint-guidelines-checker/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down Expand Up @@ -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
'''
"""
Expand Down

0 comments on commit b7c326f

Please sign in to comment.