Skip to content

Cannot parse f-string.  #4046

@Hendler

Description

@Hendler

File can not be formatted

from datetime import datetime
created = 1699960500
dt = datetime.fromtimestamp(created)
a = "hello"
n = "world"
print(f"{a}. {n} ({dt.strftime("%Y-%m-%d-%H:%M:%S")})")

And run it with these arguments:

$ black file.py

The resulting error is:

error: cannot format file.py:
Cannot parse: 9:35: print(f"{a}. {n} ({dt.strftime("%Y-%m-%d-%H:%M:%S")})")

Expected behavior

Passes black or makes correction.
Perhaps this is resolved elsewhere. e.g. #1132

Environment

  • Black's version: black==23.11.0
  • OS and Python version: MacOS 14.0 (23A344) , Python 3.12.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions