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

609: Allow __enter__() inside an __enter__() #2381

Closed
Dreamsorcerer opened this issue Mar 26, 2022 · 3 comments · Fixed by #2529
Closed

609: Allow __enter__() inside an __enter__() #2381

Dreamsorcerer opened this issue Mar 26, 2022 · 3 comments · Fixed by #2529
Assignees
Labels
bug Something isn't working

Comments

@Dreamsorcerer
Copy link
Contributor

Dreamsorcerer commented Mar 26, 2022

What's wrong

One design pattern is to wrap a context manager. It would be nice to avoid WPS609 errors with this code, which seems to require accessing the direct magic methods.

How it should be

Allow code like:

class Foo:
    ...

    def __enter__(self):
        self._conn.__enter__()
        return self

    def __exit__(self, exc_type, exc_value, traceback):
        self._conn.__exit__(exc_type, exc_value, traceback)

I guess the same for aenter/aexit as well.

@Dreamsorcerer Dreamsorcerer added the bug Something isn't working label Mar 26, 2022
@sobolevn
Copy link
Member

Yeah, I guess that calling the same magic method inside a magic method is fine.

@lensvol
Copy link
Collaborator

lensvol commented Oct 1, 2022

If it's not taken, then I could work on this.

@sobolevn
Copy link
Member

sobolevn commented Oct 1, 2022

Just note, that we allow calling all same magic methods. Not just __enter__

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants