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

Preview style removes comment in with block #3408

Closed
JelleZijlstra opened this issue Dec 9, 2022 · 1 comment
Closed

Preview style removes comment in with block #3408

JelleZijlstra opened this issue Dec 9, 2022 · 1 comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. T: bug Something isn't working

Comments

@JelleZijlstra
Copy link
Collaborator

% cat eatcomment.py 
if False:
    with xxxxxxxxxx(
        "mypy",  # mypy-c doesn't support __package__
        "py.typed",  # a marker file for type information, we assume typeshed to live in the same dir
    ) as xxxxx:
        pass
% black --diff --preview eatcomment.py
--- eatcomment.py	2022-12-09 02:39:37.001919 +0000
+++ eatcomment.py	2022-12-09 02:40:57.322777 +0000
@@ -1,6 +1,3 @@
 if False:
-    with xxxxxxxxxx(
-        "mypy",  # mypy-c doesn't support __package__
-        "py.typed",  # a marker file for type information, we assume typeshed to live in the same dir
-    ) as xxxxx:
+    with xxxxxxxxxx("mypy", "py.typed") as xxxxx:  # mypy-c doesn't support __package__
         pass
would reformat eatcomment.py

All done! ✨ 🍰 ✨
1 file would be reformatted.

Running black 22.10.0. Isolated from some code in mypy.

@JelleZijlstra JelleZijlstra added T: bug Something isn't working F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. labels Dec 9, 2022
@JelleZijlstra
Copy link
Collaborator Author

This is actually fixed on main:

% black --preview --diff --skip-magic-trailing-comma --line-length=99 eatcomment.py 
--- eatcomment.py	2022-12-09 03:08:48.840900 +0000
+++ eatcomment.py	2022-12-09 03:11:19.412154 +0000
@@ -1,6 +1,8 @@
 if False:
     with xxxxxxxxxx(
         "mypy",  # mypy-c doesn't support __package__
-        "py.typed",  # a marker file for type information, we assume typeshed to live in the same dir
+        (  # a marker file for type information, we assume typeshed to live in the same dir
+            "py.typed"
+        ),
     ) as xxxxx:
         pass
would reformat eatcomment.py

All done! ✨ 🍰 ✨
1 file would be reformatted.
% black --version
black, 22.10.1.dev24+gd4a8564 (compiled: no)
Python (CPython) 3.11.0

(Note to repro it you need --line-length=99 --skip-magic-trailing-comma)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant