-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Add "# fmt: skip" directive to black #1800
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Code makes sense to me, and the tests look to have good coverage. This looks good to me.
The lack of documentation additions scares me :-) I would like to see a quick explanation on how it works and a few examples. Although honestly the documentation needs to be restructured again since it's so messy right now. I don't know about my availability but I'll probably end up being the guy who will handle this refactor. See #1759. |
Yeah my bad there. Good call @ichard26 - If you make a plan and split up how you'd like things refactored we might be able to get help from others on that so you don't have to do it all! |
Hey guys, you want me to fill the documentation gaps, or you're on it? |
Great feature! What is the status of this PR? Friendly ping @ichard26 @cooperlees |
I got this error when I tried, looks like the first pass removes $ black skip_test.py
error: cannot format skip_test.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter. Please report a bug on https://github.com/psf/black/issues. This diff might be helpful: Log: Mode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -1,11 +1,8 @@
-z = 'hello ' + "world"
+z = "hello " + "world"
-# fmt: skip
custom_formatting = [
0, 1,
2
]
-regular_formatting = [
- 0, 1, 2, 'this will be formatted'
-]
+regular_formatting = [0, 1, 2, "this will be formatted"]
--- first pass
+++ second pass
@@ -1,8 +1,5 @@
z = "hello " + "world"
-custom_formatting = [
- 0, 1,
- 2
-]
+custom_formatting = [0, 1, 2]
regular_formatting = [0, 1, 2, "this will be formatted"] (Python 3.8.0 / macOS 10.15, |
First of all, nice catch @mrgnw ! I fixed the bug and added a unit test to validate this won't happen again. However, this is a misuse of the l = ["I", "will", "not", "be", "formatted",] # fmt: skip The following will not work: # fmt: skip
l = ["I", "will", "be", "formatted",] |
Kindly reminding that this PR is ready to be merged. |
Could you add tests that put I'm supportive of merging otherwise. |
Hey @JelleZijlstra , thank you for the response! I fixed the bug and added another unit test to check the new behavior. If you have some other edge cases you think we should address, please let me know. |
Sorry for the +1, but since this PR is ready, it would come in very handy for me, since I'm in the process of sprinkling my code with debug lines that are to be stripped on code optimization with if __debug__: log.debug(f"{large_dict=!r:.100s}") # fmt: skip |
Hey @cooperlees , @ichard26 , @JelleZijlstra, and maybe other collaborators of the Black project. This PR is almost 4 months old. I know you are busy people, and I know that this a voluntary project, but I would be very disappointed if a new version of Black would be released without it. So please, if something is missing in this PR, let me know and I'll fix/add/update it. Again, I must emphasize that I don't mean to harm anyone or to be disrespectful. I just want to see my work being used :) |
TBH, I'm a tiny bit hesitant since this may go against of Black's goal of being consistent, but since we have Thanks for your understanding and patience! |
Hey @ichard26 , thanks for the feedback! I added the missing documentation piece to the README file. Let me know if something else is missing! |
Merged. I guess I was hesitant because I'm still worried this will cause new stability bugs. I guess we'll see. Thanks for your contribution to Black! |
It doesn't work for me. In an empty file with just Tested on Python 3.9.1, black 20.8b2.dev83+g71bbb67 |
From the documentation:
|
I guess I have linked the wrong issue to this PR. The idea of this PR was to ignore lines which ends with l = ["I have", "too much space"] # fmt: skip However, the following will be formatted: # fmt: skip
l = ["I have", "too much space"] A new PR might include the ability that if Another thing that was mentioned here in the comments is that in order to check which lines to skip, Black compare the comment to specific values. Therefore, if you miss a space as @teresaejunior said, It will not ignore that line. Another PR should use regex comparison instead in order to solve this problem. |
@saroad2 It could be my specific Python version, but it doesn't work even if the space is included. And instead of just ignoring the |
@teresaejunior the newline handling being completely unaffected issue has been also reported with the old-style |
Hi, great to see this feature merged, but it seems that it cannot be used with other comments like "noqa" This will be skipped (as expected): log.debug("Long debug message") # fmt: skip This will be formatted: log.debug("Long debug message, so we ignore flake8's E501 long line message") # fmt: skip # noqa: E501 Should I create an issue about it? Or is it how For example |
Please open a new issue. I feel like it should work as you expect, but others may disagree. |
For any one (like me) searching: #2213 |
Fixes #1162
After being requested for quite some time, implemented the ability to skip formatting only one line using
#fmt: skip
😄 .