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

Suggestion: Mention contextlib.ExitStack in "Use backslashes for with statements"? #2560

Closed
joshua-cannon-techlabs opened this issue Oct 22, 2021 · 3 comments · Fixed by #3247
Labels
good first issue Good for newcomers T: documentation Improvements to the docs (e.g. new topic, correction, etc)

Comments

@joshua-cannon-techlabs
Copy link

Is this related to a problem? Please describe.

On Black's future style doc it talks about black handling a with with multiple context managers in a few ways (Python-version-dependent).

Describe the solution you'd like

Black should suggest to the user (in documentation only) that if they don't like Black's current or future behavior, that constructing a contextlib.ExitStack can help the issue while maintaining 95%-ish of the code readability and has minimal overhead.

As an example (feel free to steal), and using the existing code on that page

with contextlib.ExitStack() as exit_stack:
    cm1 = exit_stack.enter_context(make_context_manager(1))
    cm2 = exit_stack.enter_context(make_context_manager(2))
    cm3 = exit_stack.enter_context(make_context_manager(3))
    cm4 = exit_stack.enter_context(make_context_manager(4))
    ...

Describe alternatives you've considered

N/A

Additional context

❤️ black

@joshua-cannon-techlabs joshua-cannon-techlabs added the T: documentation Improvements to the docs (e.g. new topic, correction, etc) label Oct 22, 2021
@joshua-cannon-techlabs
Copy link
Author

Related: #2118 #1948

@ichard26 ichard26 added the good first issue Good for newcomers label Dec 14, 2021
@Anika-Roy
Copy link

i would like to work on this.Im a beginner

@ichard26
Copy link
Collaborator

Hi @Anika-Roy! Happy to see you'd like to contribute to Black! You should first take a look at https://black.readthedocs.io/en/latest/contributing/the_basics.html which provides an overview on contributing.

I know our contributing documentation is lacking (matter of fact I'm currently working on rewriting them to be way better), so please don't worry about asking too many questions. If you use Discord, feel free to chat with us in the #black-formatter channel on Python Discord


For this issue specifically, since it only involves documentation, things are a lot simpler. Basically you should fork the repository, clone your fork, edit https://github.com/psf/black/blob/main/docs/the_black_code_style/future_style.md to include a few more paragraphs under the "Using backslashes for with statements" header according to the issue description. Actually, you could do all of this using the GitHub web editor instead, i.e. press .

Finally, make a PR with your changes to that one document and we'll start the review process. I'll share more on that once we get to that point :)

Good luck!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers T: documentation Improvements to the docs (e.g. new topic, correction, etc)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants