This commit is contained in:
Arseniy Poroshin 2025-12-16 16:39:34 -05:00 committed by GitHub
commit 29ab47a3f9
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 8 additions and 1 deletions

View File

@ -29,6 +29,9 @@ datetime.datetime.strptime("something", something).astimezone()
# OK # OK
datetime.datetime.strptime("something", something).replace(tzinfo=datetime.timezone.utc) datetime.datetime.strptime("something", something).replace(tzinfo=datetime.timezone.utc)
# OK
datetime.datetime.strptime("something", "something").date()
from datetime import datetime from datetime import datetime
# no replace orastimezone unqualified # no replace orastimezone unqualified

View File

@ -21,6 +21,10 @@ use crate::rules::flake8_datetimez::helpers::DatetimeModuleAntipattern;
/// `datetime.datetime.strptime()` without `%z` returns a naive datetime /// `datetime.datetime.strptime()` without `%z` returns a naive datetime
/// object. Follow it with `.replace(tzinfo=<timezone>)` or `.astimezone()`. /// object. Follow it with `.replace(tzinfo=<timezone>)` or `.astimezone()`.
/// ///
/// To make a naive date object on Python 3.13 and earlier, follow it with
/// `datetime.datetime.strptime()` with `.date()`.
/// On Python 3.14 and later, use `datetime.date.strptime()`.
///
/// ## Example /// ## Example
/// ```python /// ```python
/// import datetime /// import datetime
@ -155,7 +159,7 @@ fn find_antipattern(
return Some(DatetimeModuleAntipattern::NoTzArgumentPassed); return Some(DatetimeModuleAntipattern::NoTzArgumentPassed);
}; };
// Ex) `datetime.strptime(...).astimezone()` // Ex) `datetime.strptime(...).astimezone()`
if attr == "astimezone" { if attr == "astimezone" || attr == "date" {
return None; return None;
} }
if attr != "replace" { if attr != "replace" {