Skip to content

Commit 1b789e3

Browse files
ntBreMichaReiser
authored andcommitted
[flake8-datetimez] Stabilize datetime-min-max (DTZ901) (#16635)
Summary -- Stabilizes DTZ901, renames the rule function to match the rule name, removes the `preview_rules` test, and handles some nits in the docs (mention `min` first to match the rule name too). Test Plan -- 1 closed issue on 2024-11-12, 4 days after the rule was added. No issues since
1 parent 4afb5da commit 1b789e3

4 files changed

Lines changed: 8 additions & 22 deletions

File tree

crates/ruff_linter/src/checkers/ast/analyze/expression.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ pub(crate) fn expression(expr: &Expr, checker: &Checker) {
428428
flake8_2020::rules::name_or_attribute(checker, expr);
429429
}
430430
if checker.enabled(Rule::DatetimeMinMax) {
431-
flake8_datetimez::rules::datetime_max_min(checker, expr);
431+
flake8_datetimez::rules::datetime_min_max(checker, expr);
432432
}
433433
if checker.enabled(Rule::BannedApi) {
434434
flake8_tidy_imports::rules::banned_attribute_access(checker, expr);

crates/ruff_linter/src/codes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,7 @@ pub fn code_to_rule(linter: Linter, code: &str) -> Option<(RuleGroup, Rule)> {
719719
(Flake8Datetimez, "007") => (RuleGroup::Stable, rules::flake8_datetimez::rules::CallDatetimeStrptimeWithoutZone),
720720
(Flake8Datetimez, "011") => (RuleGroup::Stable, rules::flake8_datetimez::rules::CallDateToday),
721721
(Flake8Datetimez, "012") => (RuleGroup::Stable, rules::flake8_datetimez::rules::CallDateFromtimestamp),
722-
(Flake8Datetimez, "901") => (RuleGroup::Preview, rules::flake8_datetimez::rules::DatetimeMinMax),
722+
(Flake8Datetimez, "901") => (RuleGroup::Stable, rules::flake8_datetimez::rules::DatetimeMinMax),
723723

724724
// pygrep-hooks
725725
(PygrepHooks, "001") => (RuleGroup::Removed, rules::pygrep_hooks::rules::Eval),

crates/ruff_linter/src/rules/flake8_datetimez/mod.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ mod tests {
99
use test_case::test_case;
1010

1111
use crate::registry::Rule;
12-
use crate::settings::types::PreviewMode;
1312
use crate::test::test_path;
1413
use crate::{assert_messages, settings};
1514

@@ -22,6 +21,7 @@ mod tests {
2221
#[test_case(Rule::CallDatetimeStrptimeWithoutZone, Path::new("DTZ007.py"))]
2322
#[test_case(Rule::CallDateToday, Path::new("DTZ011.py"))]
2423
#[test_case(Rule::CallDateFromtimestamp, Path::new("DTZ012.py"))]
24+
#[test_case(Rule::DatetimeMinMax, Path::new("DTZ901.py"))]
2525
fn rules(rule_code: Rule, path: &Path) -> Result<()> {
2626
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
2727
let diagnostics = test_path(
@@ -31,18 +31,4 @@ mod tests {
3131
assert_messages!(snapshot, diagnostics);
3232
Ok(())
3333
}
34-
35-
#[test_case(Rule::DatetimeMinMax, Path::new("DTZ901.py"))]
36-
fn preview_rules(rule_code: Rule, path: &Path) -> Result<()> {
37-
let snapshot = format!("{}_{}", rule_code.noqa_code(), path.to_string_lossy());
38-
let diagnostics = test_path(
39-
Path::new("flake8_datetimez").join(path).as_path(),
40-
&settings::LinterSettings {
41-
preview: PreviewMode::Enabled,
42-
..settings::LinterSettings::for_rule(rule_code)
43-
},
44-
)?;
45-
assert_messages!(snapshot, diagnostics);
46-
Ok(())
47-
}
4834
}

crates/ruff_linter/src/rules/flake8_datetimez/rules/datetime_min_max.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,18 @@ use ruff_text_size::Ranged;
99
use crate::checkers::ast::Checker;
1010

1111
/// ## What it does
12-
/// Checks for uses of `datetime.datetime.max` and `datetime.datetime.min`.
12+
/// Checks for uses of `datetime.datetime.min` and `datetime.datetime.max`.
1313
///
1414
/// ## Why is this bad?
15-
/// `datetime.max` and `datetime.min` are non-timezone-aware datetime objects.
15+
/// `datetime.min` and `datetime.max` are non-timezone-aware datetime objects.
1616
///
17-
/// As such, operations on `datetime.max` and `datetime.min` may behave
17+
/// As such, operations on `datetime.min` and `datetime.max` may behave
1818
/// unexpectedly, as in:
1919
///
2020
/// ```python
2121
/// # Timezone: UTC-14
22-
/// datetime.max.timestamp() # ValueError: year 10000 is out of range
2322
/// datetime.min.timestamp() # ValueError: year 0 is out of range
23+
/// datetime.max.timestamp() # ValueError: year 10000 is out of range
2424
/// ```
2525
///
2626
/// ## Example
@@ -53,7 +53,7 @@ impl Violation for DatetimeMinMax {
5353
}
5454

5555
/// DTZ901
56-
pub(crate) fn datetime_max_min(checker: &Checker, expr: &Expr) {
56+
pub(crate) fn datetime_min_max(checker: &Checker, expr: &Expr) {
5757
let semantic = checker.semantic();
5858

5959
if !semantic.seen_module(Modules::DATETIME) {

0 commit comments

Comments
 (0)