feat: add more DTZ fix suggestions in messages (#2274)

This commit is contained in:
Ville Skyttä 2023-01-28 01:14:17 +02:00 committed by GitHub
parent 8149c8cbc4
commit 221b87332c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 10 deletions

View File

@ -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)

View File

@ -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"
)
}
}