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

multiple with open with long file names on same statement #1719

Closed
capitalaslash opened this issue Sep 22, 2020 · 4 comments
Closed

multiple with open with long file names on same statement #1719

capitalaslash opened this issue Sep 22, 2020 · 4 comments
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@capitalaslash
Copy link

Describe the style change Better management of multiple with open on same statement

Examples in the current Black style

with open("a_very_long_file_name", "w") as a, open(
    "another_very_long_filename", "w"
) as b:
     pass

Desired style How do you think Black should format the above snippets:

with open("a_very_long_file_name", "w") as a, \
     open("another_very_long_filename", "w") as b:
    pass

Additional context yapf keeps the snippet as shown in the desired section, autopep8 adds an indentation for the second line. No solution is really great, but black's solution is really unreadable imho.

@capitalaslash capitalaslash added the T: style What do we want Blackened code to look like? label Sep 22, 2020
@sjohannes
Copy link

This duplicates #557 and #664 I think?

@ichard26 ichard26 added T: bug Something isn't working R: duplicate This issue or pull request already exists and removed T: style What do we want Blackened code to look like? labels Oct 7, 2020
@ichard26
Copy link
Collaborator

ichard26 commented Oct 7, 2020

Yeah fair enough - I didn't take a deep look as I didn't want to explain how we in fact have plans to handle multiple context managers better even though it looks like this better handling has landed already since this corner case is detailed in the documentation :-)

Thanks @sjohannes!

this counts as a bug as the expected behaviour has been documented

@ichard26 ichard26 closed this as completed Oct 7, 2020
@capitalaslash
Copy link
Author

The documentation saying that this should work is quite confusing...
I understand that #664 is still in the works and it requires 3.9, or will it work also on older versions?

@ichard26
Copy link
Collaborator

ichard26 commented Oct 7, 2020

@capitalaslash yeah unfortunately the documentation has been added before the actual support has been added. The plan in #664 will work on older Python versions as we are special casing context managers. See #664 (comment) and the comment below it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants