Avoid DTZ007 false-positives for non-string arguments (#1300)
This commit is contained in:
@@ -23,6 +23,12 @@ datetime.datetime.strptime("something", "something").astimezone()
|
||||
# OK
|
||||
datetime.datetime.strptime("something", "%H:%M:%S%z")
|
||||
|
||||
# OK
|
||||
datetime.datetime.strptime("something", something).astimezone()
|
||||
|
||||
# OK
|
||||
datetime.datetime.strptime("something", something).replace(tzinfo=datetime.timezone.utc)
|
||||
|
||||
from datetime import datetime
|
||||
|
||||
# no replace orastimezone unqualified
|
||||
|
||||
@@ -177,22 +177,17 @@ pub fn call_datetime_strptime_without_zone(
|
||||
return;
|
||||
}
|
||||
|
||||
let Some(ExprKind::Constant {
|
||||
// Does the `strptime` call contain a format string with a timezone specifier?
|
||||
if let Some(ExprKind::Constant {
|
||||
value: Constant::Str(format),
|
||||
kind: None,
|
||||
}) = args.get(1).as_ref().map(|arg| &arg.node) else {
|
||||
checker.add_check(Check::new(
|
||||
CheckKind::CallDatetimeStrptimeWithoutZone,
|
||||
location,
|
||||
));
|
||||
return;
|
||||
}) = args.get(1).as_ref().map(|arg| &arg.node)
|
||||
{
|
||||
if format.contains("%z") {
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// Does the `strptime` call contain a format string with a timezone specifier?
|
||||
if format.contains("%z") {
|
||||
return;
|
||||
}
|
||||
|
||||
let (Some(grandparent), Some(parent)) = (checker.current_expr_grandparent(), checker.current_expr_parent()) else {
|
||||
checker.add_check(Check::new(
|
||||
CheckKind::CallDatetimeStrptimeWithoutZone,
|
||||
|
||||
@@ -36,10 +36,10 @@ expression: checks
|
||||
fix: ~
|
||||
- kind: CallDatetimeStrptimeWithoutZone
|
||||
location:
|
||||
row: 29
|
||||
row: 35
|
||||
column: 0
|
||||
end_location:
|
||||
row: 29
|
||||
row: 35
|
||||
column: 43
|
||||
fix: ~
|
||||
|
||||
|
||||
Reference in New Issue
Block a user