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

Black fails to format string which has '='s etc #4361

Closed
rushiagr opened this issue May 13, 2024 · 2 comments
Closed

Black fails to format string which has '='s etc #4361

rushiagr opened this issue May 13, 2024 · 2 comments
Labels
F: docstrings How we format docstrings T: bug Something isn't working

Comments

@rushiagr
Copy link

Describe the bug

For a particular string in my source, it is not able to format.

To Reproduce
Please see below output produced by black

--- src
+++ dst
@@ -81541,11 +81541,11 @@
             value=
             Constant(
                 kind=
                 None,  # NoneType
                 value=
-                "\n    ===============================================================================================\n    \n    # NOTE: when parquet generation script is stopped accidentally (some parquet files already generated, but not all), \n    #   and need to restart (worked on 13 May 2024):\n    \n    1. Delete all today's files in /tmp/quotefiles/[parquet|extracted]\n    2. Delete all today's files in s3 bucket rushitestbucket2/kitedata/pq10secquotes[|bn|fn|mn|sn]\n    3. Uncompress allquotes and allinstruments files back to /drive/kitedata:\n        cd /drive/kitedata/compressed/quotes\n        gunzip -c allquotes-2024-05-13  >  /drive/kitedata/allquotes-2024-05-13\n        cd /drive/kitedata/compressed/instruments\n        gunzip -c  allinstruments-2024-05-13  >  /drive/kitedata/allinstruments-2024-05-13\n    4. Run generate_all_parquet_files via automation (change time to be immediately after current time)\n    \n    # NOTE: below methods didn't work for some reason, in this particular case\n    \n    ==============================================================================================\n    \n    Command used to locally test midcpnifty and sensex parquet generation:\n    python squash.py --generate-parquet-files --dates-to-process 2023-08-03,2023-08-04 --index MIDCPNIFTY --skip-upload\n    python squash.py --generate-parquet-files --dates-to-process 2023-08-03,2023-08-04 --index SENSEX --skip-upload\n    ",  # str
+                "\n    ===============================================================================================\n\n    # NOTE: when parquet generation script is stopped accidentally (some parquet files already generated, but not all),\n    #   and need to restart (worked on 13 May 2024):\n\n    1. Delete all today's files in /tmp/quotefiles/[parquet|extracted]\n    2. Delete all today's files in s3 bucket rushitestbucket2/kitedata/pq10secquotes[|bn|fn|mn|sn]\n    3. Uncompress allquotes and allinstruments files back to /drive/kitedata:\n        cd /drive/kitedata/compressed/quotes\n        gunzip -c allquotes-2024-05-13  >  /drive/kitedata/allquotes-2024-05-13\n        cd /drive/kitedata/compressed/instruments\n        gunzip -c  allinstruments-2024-05-13  >  /drive/kitedata/allinstruments-2024-05-13\n    4. Run generate_all_parquet_files via automation (change time to be immediately after current time)\n\n    # NOTE: below methods didn't work for some reason, in this particular case\n\n    ==============================================================================================\n\n    Command used to locally test midcpnifty and sensex parquet generation:\n    python squash.py --generate-parquet-files --dates-to-process 2023-08-03,2023-08-04 --index MIDCPNIFTY --skip-upload\n    python squash.py --generate-parquet-files --dates-to-process 2023-08-03,2023-08-04 --index SENSEX --skip-upload\n    ",  # str
             )  # /Constant
         )  # /Expr
         Expr(
             value=
             Constant(

Error message:

error: cannot format /Users/a/b/c/d.py: INTERNAL ERROR: Black produced code that is not equivalent to the source.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /var/folders/5j/cgflppss17d3hs6zb_hyyrzw0000gn/T/blk_ummt734r.log

Expected behavior

Black should be able to reformat file
Environment

  • Black's version:
black==24.3.0
  • OS and Python version: mac sonoma, python version 3.11.4

Additional context

Apologies as I'm not able to search duplicates in issue tracker, as i'm not well-versed with black and the bugs here..

@rushiagr rushiagr added the T: bug Something isn't working label May 13, 2024
@rushiagr
Copy link
Author

OK looks like the issue is with (trailing) whitespaces. I removed trailing whitespaces from the code, and black was able to format. Providing before (buggy) and after (black works):

Before: https://gist.github.com/rushiagr/78b01515286ee86696e3209970b73a3c

After: https://gist.github.com/rushiagr/437fef5046a4436673813e4cd6e8c992

I just redacted s3 bucket name to 'mys3bucket', else the code snippet was lifted as-is

@JelleZijlstra JelleZijlstra added the F: docstrings How we format docstrings label May 13, 2024
@hauntsaninja
Copy link
Collaborator

Thanks, I don't quite follow your example, but I believe it should be fixed in Black 24.4.0 and newer (by #4290). Please re-open if not!

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

No branches or pull requests

3 participants