Skip to content

DTZ007 with F-string format specifier #10601

@MichaReiser

Description

@MichaReiser
          Don't know if this is the same issue, but there is also a false-positive if the format string is an f-string.

For example:

from datetime import datetime
def parse_iso(iso_str,millis=True):
    return datetime.strptime(iso_str, f"%Y-%m-%dT%H:%M:%S{('.%f' if millis else '')}%z")

Even without a condition inside the f-string, it immediately triggers the lint error.

For example:

from datetime import datetime
dt = datetime.strptime("","%Y-%m-%d %H:%M:%S%z") # everything okay

dt = datetime.strptime("", f"%Y-%m-%d %H:%M:%S%z") # throws DTZ007

Originally posted by @jonas-w in #1306 (comment)

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingruleImplementing or modifying a lint rule

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions