diff --git a/pylint/checkers/classes/special_methods_checker.py b/pylint/checkers/classes/special_methods_checker.py index 7eb61440df..d3d2b0935e 100644 --- a/pylint/checkers/classes/special_methods_checker.py +++ b/pylint/checkers/classes/special_methods_checker.py @@ -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: diff --git a/pylint/checkers/typecheck.py b/pylint/checkers/typecheck.py index 8f5f35b6fe..7cb132830e 100644 --- a/pylint/checkers/typecheck.py +++ b/pylint/checkers/typecheck.py @@ -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 = { @@ -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) diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py index f53ae88456..f8b7b74e30 100644 --- a/pylint/checkers/utils.py +++ b/pylint/checkers/utils.py @@ -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)