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

False-positive E1133 (not-an-iterable) for iterable context manager #3233

Closed
tucked opened this issue Nov 7, 2019 · 3 comments
Closed

False-positive E1133 (not-an-iterable) for iterable context manager #3233

tucked opened this issue Nov 7, 2019 · 3 comments
Assignees
Labels

Comments

@tucked
Copy link

tucked commented Nov 7, 2019

Steps to reproduce

"""sscce.py"""

class Context:
    def __enter__(self):
        return self
    def __exit__(self, type_, exc, traceback):
        return False

class Iterable(Context):
    def __iter__(self):
        return self
    def __next__(self):
        return self

class Foo(Iterable):
    pass

with Foo() as foo:
    for s in foo:
        print(s)

Note: I built this SSCCE from a real-world error I got using paramiko.SFTPFile:

        with self._sftp.open(local_path, mode='r') as local_file:
            for line in local_file:  # triggers on local_file
                yield line.rstrip()

SFTPFile is like Foo. It inherits from paramiko.BufferedFile which is analogous to Iterable, and BufferedFile inherits from paramiko.util.ClosingContextManager.

Current behavior

sscce.py:19:13: E1133: Non-iterable value foo is used in an iterating context (not-an-iterable)

Expected behavior

(no errors)

pylint --version output

pylint 2.4.3
astroid 2.3.3
Python 3.6.8 (default, Oct  7 2019, 12:59:55)
[GCC 8.3.0]
@PCManticore
Copy link
Contributor

Thank you for the clear example, I can confirm the bug.

@cdce8p
Copy link
Member

cdce8p commented Oct 17, 2021

This issue seems to be fixed when testing with the latest pylint version.
If you still encounter issues, please report back and I'll reopen it.

@cdce8p cdce8p closed this as completed Oct 17, 2021
@tucked
Copy link
Author

tucked commented Oct 26, 2021

Yes, I can no longer repro either.
This seems to have been fixed in 2.5.0, though I suspect that the fix was in astroid because:

python3.6 -m venv venv
venv/bin/python -m pip install pylint==2.4.4
venv/bin/pylint sscce.py  # repro
venv/bin/python -m pip install astroid~=2.4.0
venv/bin/pylint sscce.py  # NO repro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants