Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

not-an-iterable false positive with decorator #9251

Closed
JulienPalard opened this issue Nov 21, 2023 · 1 comment
Closed

not-an-iterable false positive with decorator #9251

JulienPalard opened this issue Nov 21, 2023 · 1 comment
Labels
Decorators Duplicate 🐫 Duplicate of an already existing issue False Positive 🦟 A message is emitted but nothing is wrong with the code

Comments

@JulienPalard
Copy link
Contributor

JulienPalard commented Nov 21, 2023

Bug description

This reproducer uses a decorator to make a normal function an infinite iterable, sadly pylint don't get it:

"""repro.py file"""

from itertools import count


class IteratorFromFunction: # pylint: disable=too-few-public-methods
    """Builds an iterator based on a function."""

    def __init__(self, function):
        """Build a new sequence."""
        self.function = function

    def __iter__(self):
        """Iterate over the integer sequence."""
        for i in count():
            yield self.function(i)


@IteratorFromFunction
def i_am_iterable(i):
    """Sequence of square numbers."""
    return i ** 2


def main():
    """just to check it works"""
    for i in i_am_iterable:
        print(i)
        if i > 100:
            break

if __name__ == "__main__":
    main()

Configuration

No response

Command used

pylint repro.py

Pylint output

$ pylint repro.py
************* Module repro
repro.py:27:13: E1133: Non-iterable value i_am_iterable is used in an iterating context (not-an-iterable)

------------------------------------------------------------------
Your code has been rated at 6.88/10 (previous run: 6.88/10, +0.00)

Expected behavior

The decorator actually replace the function with an iterable, so pylint should not tell it's not.

Pylint version

pylint 3.0.2
astroid 3.0.1
Python 3.11.6 (main, Oct  8 2023, 05:06:43) [GCC 13.2.0]

OS / Environment

Debian Trixie

Additional dependencies

No response

@JulienPalard JulienPalard added the Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling label Nov 21, 2023
@Pierre-Sassoulas Pierre-Sassoulas added Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning False Positive 🦟 A message is emitted but nothing is wrong with the code and removed Needs triage 📥 Just created, needs acknowledgment, triage, and proper labelling labels Nov 21, 2023
@jacobtylerwalls
Copy link
Member

Duplicate of #1694

@jacobtylerwalls jacobtylerwalls marked this as a duplicate of #1694 Mar 1, 2024
@jacobtylerwalls jacobtylerwalls closed this as not planned Won't fix, can't repro, duplicate, stale Mar 1, 2024
@jacobtylerwalls jacobtylerwalls added Duplicate 🐫 Duplicate of an already existing issue and removed Needs investigation 🔬 A bug or crash where it's not immediately obvious what is happenning labels Mar 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Decorators Duplicate 🐫 Duplicate of an already existing issue False Positive 🦟 A message is emitted but nothing is wrong with the code
Projects
None yet
Development

No branches or pull requests

3 participants