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

cannot format xxxxx.py: Cannot parse: 219:50: xxxxx = f"TEST{now.strftime("%Y%m%d%H%M%S")}{random.randint(1,9999):0>4}" #517

Closed
godtang opened this issue Jun 11, 2024 · 7 comments
Assignees
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Issue is not triaged.

Comments

@godtang
Copy link

godtang commented Jun 11, 2024

Diagnostic Data

  • Python version (& distribution if applicable, e.g., Anaconda): 3.12.4
  • Type of virtual environment used (e.g., conda, venv, virtualenv, etc.): no , win 10 app store install python
  • Operating system (and version): , win 10
  • Version of tool extension you are using: vscode v2024.2.0

Behaviour

Expected Behavior

reformatted succ

Actual Behavior

Cannot parse

Reproduction Steps:

now = datetime.now()
tmp = f"TEST{now.strftime("%Y%m%d%H%M%S")}{random.randint(1,9999):0>4}"

Logs:

Click here for detailed logs 2024-06-11 15:38:40.561 [info] error: cannot format xxxxx.py: Cannot parse: 219:52: xxxx = f"TEST{now.strftime("%Y%m%d%H%M%S")}{random.randint(1,9999):0>4}"

Oh no! 💥 💔 💥
1 file failed to reformat.

Outcome When Attempting Debugging Steps:

Did running it from the command line work?

Extra Details

@godtang godtang added the bug Issue identified by VS Code Team member as probable bug label Jun 11, 2024
@github-actions github-actions bot added the triage-needed Issue is not triaged. label Jun 11, 2024
@karthiknadig
Copy link
Member

@godtang This is coming from Black itself. Does it work when you try to format it from command line?

@karthiknadig karthiknadig self-assigned this Jun 11, 2024
@godtang
Copy link
Author

godtang commented Jun 12, 2024

@godtang This is coming from Black itself. Does it work when you try to format it from command line?

sorry , i don't know how to format from command line

@godtang
Copy link
Author

godtang commented Jun 15, 2024

image
i try it, and black work

@karthiknadig
Copy link
Member

What is the version of black where it worked? python -m black —version should tell you.

@godtang
Copy link
Author

godtang commented Jun 16, 2024

What is the version of black where it worked? python -m black —version should tell you.

python.exe -m black --version
python -m black, 24.4.2 (compiled: yes)
Python (CPython) 3.12.4
image

@wbkboyer
Copy link

Hey @godtang ! I think I've discovered how to resolve your issue: could you try to replace the double-quotes with single-quotes inside your f-string curly braces (i.e. inside your call to now.strftime())?

In my use-case:

2024-07-17 18:18:39.086 [info] error: cannot format XXXXXXX: Cannot parse: 398:34:                     f"|{data.get("infilename"):<{infilename_len}}"

Oh no! 💥 💔 💥
1 file failed to reformat.

After changing inner double-quotes to single-quotes:

outfile.write(
    f"|{data.get('infilename'):<{infilename_len}}"
    ...
)

Both the VSCode black extension (ms-python.black-formatter ships with black=24.3.0.) and black, 24.4.2 now succeed:

2024-07-17 18:32:19.912 [info] reformatted XXXXXX

All done! ✨ 🍰 ✨
1 file reformatted.

@karthiknadig
Copy link
Member

karthiknadig commented Oct 1, 2024

Closing this, since the build in black is updated in the pre-release to latest.

@karthiknadig karthiknadig closed this as not planned Won't fix, can't repro, duplicate, stale Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue identified by VS Code Team member as probable bug triage-needed Issue is not triaged.
Projects
None yet
Development

No branches or pull requests

3 participants