From 221b87332c25babc4077a5d7cf8177d473d2cfea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Sat, 28 Jan 2023 01:14:17 +0200 Subject: [PATCH] feat: add more DTZ fix suggestions in messages (#2274) --- README.md | 10 +++++----- src/violations.rs | 25 ++++++++++++++++++++----- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 25eac7effc..f39b83826b 100644 --- a/README.md +++ b/README.md @@ -938,14 +938,14 @@ For more, see [flake8-datetimez](https://pypi.org/project/flake8-datetimez/) on | Code | Name | Message | Fix | | ---- | ---- | ------- | --- | | DTZ001 | call-datetime-without-tzinfo | The use of `datetime.datetime()` without `tzinfo` argument is not allowed | | -| DTZ002 | call-datetime-today | The use of `datetime.datetime.today()` is not allowed | | -| DTZ003 | call-datetime-utcnow | The use of `datetime.datetime.utcnow()` is not allowed | | -| DTZ004 | call-datetime-utcfromtimestamp | The use of `datetime.datetime.utcfromtimestamp()` is not allowed | | +| DTZ002 | call-datetime-today | The use of `datetime.datetime.today()` is not allowed, use `datetime.datetime.now(tz=)` instead | | +| DTZ003 | call-datetime-utcnow | The use of `datetime.datetime.utcnow()` is not allowed, use `datetime.datetime.now(tz=)` instead | | +| DTZ004 | call-datetime-utcfromtimestamp | The use of `datetime.datetime.utcfromtimestamp()` is not allowed, use `datetime.datetime.fromtimestamp(ts, tz=)` instead | | | DTZ005 | call-datetime-now-without-tzinfo | The use of `datetime.datetime.now()` without `tz` argument is not allowed | | | DTZ006 | call-datetime-fromtimestamp | The use of `datetime.datetime.fromtimestamp()` without `tz` argument is not allowed | | | DTZ007 | call-datetime-strptime-without-zone | The use of `datetime.datetime.strptime()` without %z must be followed by `.replace(tzinfo=)` or `.astimezone()` | | -| DTZ011 | call-date-today | The use of `datetime.date.today()` is not allowed. | | -| DTZ012 | call-date-fromtimestamp | The use of `datetime.date.fromtimestamp()` is not allowed | | +| DTZ011 | call-date-today | The use of `datetime.date.today()` is not allowed, use `datetime.datetime.now(tz=).date()` instead | | +| DTZ012 | call-date-fromtimestamp | The use of `datetime.date.fromtimestamp()` is not allowed, use `datetime.datetime.fromtimestamp(ts, tz=).date()` instead | | ### flake8-debugger (T10) diff --git a/src/violations.rs b/src/violations.rs index 64d0b69961..43edca5e16 100644 --- a/src/violations.rs +++ b/src/violations.rs @@ -4061,7 +4061,10 @@ define_violation!( impl Violation for CallDatetimeToday { #[derive_message_formats] fn message(&self) -> String { - format!("The use of `datetime.datetime.today()` is not allowed") + format!( + "The use of `datetime.datetime.today()` is not allowed, use \ + `datetime.datetime.now(tz=)` instead" + ) } } @@ -4071,7 +4074,10 @@ define_violation!( impl Violation for CallDatetimeUtcnow { #[derive_message_formats] fn message(&self) -> String { - format!("The use of `datetime.datetime.utcnow()` is not allowed") + format!( + "The use of `datetime.datetime.utcnow()` is not allowed, use \ + `datetime.datetime.now(tz=)` instead" + ) } } @@ -4081,7 +4087,10 @@ define_violation!( impl Violation for CallDatetimeUtcfromtimestamp { #[derive_message_formats] fn message(&self) -> String { - format!("The use of `datetime.datetime.utcfromtimestamp()` is not allowed") + format!( + "The use of `datetime.datetime.utcfromtimestamp()` is not allowed, use \ + `datetime.datetime.fromtimestamp(ts, tz=)` instead" + ) } } @@ -4126,7 +4135,10 @@ define_violation!( impl Violation for CallDateToday { #[derive_message_formats] fn message(&self) -> String { - format!("The use of `datetime.date.today()` is not allowed.") + format!( + "The use of `datetime.date.today()` is not allowed, use \ + `datetime.datetime.now(tz=).date()` instead" + ) } } @@ -4136,7 +4148,10 @@ define_violation!( impl Violation for CallDateFromtimestamp { #[derive_message_formats] fn message(&self) -> String { - format!("The use of `datetime.date.fromtimestamp()` is not allowed") + format!( + "The use of `datetime.date.fromtimestamp()` is not allowed, use \ + `datetime.datetime.fromtimestamp(ts, tz=).date()` instead" + ) } }