False-positive `DTZ007`: The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)`
- Dominant language
- Rust
- Stars
- 49.6k
- Forks
- 2.4k
- Avg merge
- 2d 1h
- Merged PRs (30d)
- 445
Description
```python
import datetime
DT_FORMAT = "%a, %d %b %Y %H:%M:%S %z"
file_data = "Fri, 23 Sep 2022 08:42:36 +0000"
parsed_date = datetime.datetime.strptime(
file_data, DT_FORMAT
)
```
```console
$ ruff test_ruff_DTZ007.py
Found 1 error(s).
test_ruff_DTZ007.py:7:15: DTZ007 The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)`
```
Contributor guide
Research direction
Start by running the provided `ruff test_ruff_DTZ007.py` reproduction and inspect the DTZ007 rule that reports the example. The change is done when a `strptime()` call whose format contains `%z` no longer produces a false-positive DTZ007 diagnostic, while the existing warning remains for formats without `%z`.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100