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

PLC2801 false positive when __exit__ is not called #9499

Closed
DetachHead opened this issue Jan 12, 2024 · 1 comment
Closed

PLC2801 false positive when __exit__ is not called #9499

DetachHead opened this issue Jan 12, 2024 · 1 comment

Comments

@DetachHead
Copy link

i have a context manager that wraps another context manager, eg:

from contextlib import AbstractContextManager

class Wrapped:
    def __init__(self, cm: AbstractContextManager[None]):
        self.cm = cm

    def __enter__(self):
        self.cm.__enter__() # PLC2801: Unnecessary dunder call to `__enter__`

    def __exit__(self):
        self.cm.__exit__(None, None, None)

playground

in this case, i can't replace the __enter__ call with a with statement because __exit__ is not called in the same place. ruff should be able to detect cases like this where __enter__ is called on its own

@charliermarsh
Copy link
Member

I believe this is fixed by #9496

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

No branches or pull requests

2 participants