Skip to content

Commit

Permalink
Handle ComprehensionScope and their behaviour better (#5923)
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord committed Mar 15, 2022
1 parent 9755505 commit 0481a73
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
5 changes: 5 additions & 0 deletions pylint/checkers/classes/special_methods_checker.py
Expand Up @@ -289,6 +289,11 @@ def _is_iterator(node):
if isinstance(node, astroid.bases.Generator):
# Generators can be iterated.
return True
# pylint: disable-next=fixme
# TODO: Should be covered by https://github.com/PyCQA/astroid/pull/1475
if isinstance(node, nodes.ComprehensionScope):
# Comprehensions can be iterated.
return True

if isinstance(node, astroid.Instance):
try:
Expand Down
10 changes: 5 additions & 5 deletions pylint/checkers/typecheck.py
Expand Up @@ -273,11 +273,11 @@ def _missing_member_hint(owner, attrname, distance_threshold, max_choices):

names = [repr(name) for name in names]
if len(names) == 1:
names = ", ".join(names)
names_hint = ", ".join(names)
else:
names = f"one of {', '.join(names[:-1])} or {names[-1]}"
names_hint = f"one of {', '.join(names[:-1])} or {names[-1]}"

return f"; maybe {names}?"
return f"; maybe {names_hint}?"


MSGS = {
Expand Down Expand Up @@ -2047,10 +2047,10 @@ def _is_asyncio_coroutine(node):
return False

def _check_iterable(self, node, check_async=False):
if is_inside_abstract_class(node) or is_comprehension(node):
if is_inside_abstract_class(node):
return
inferred = safe_infer(node)
if not inferred:
if not inferred or is_comprehension(inferred):
return
if not is_iterable(inferred, check_async=check_async):
self.add_message("not-an-iterable", args=node.as_string(), node=node)
Expand Down
5 changes: 5 additions & 0 deletions pylint/checkers/utils.py
Expand Up @@ -1189,6 +1189,11 @@ def _supports_protocol(
if protocol_callback(value):
return True

# pylint: disable-next=fixme
# TODO: Should be covered by https://github.com/PyCQA/astroid/pull/1475
if isinstance(value, nodes.ComprehensionScope):
return True

if (
isinstance(value, astroid.bases.Proxy)
and isinstance(value._proxied, astroid.BaseInstance)
Expand Down

0 comments on commit 0481a73

Please sign in to comment.