From d04367a042433f2f307618b30986053c05c06670 Mon Sep 17 00:00:00 2001 From: rembridge <35376887+arembridge@users.noreply.github.com> Date: Thu, 27 Jul 2023 00:21:03 +0100 Subject: [PATCH] call-datetime-without-tzinfo comment (#6105) ## Summary Updated doc comment for `call_datetime_without_tzinfo.rs`. Online docs also benefit from this update. ## Test Plan Checked docs via [mkdocs](https://github.com/astral-sh/ruff/blob/389fe13c934fe73679474006412b1eded4a2cad0/CONTRIBUTING.md?plain=1#L267-L296) --- .../rules/call_datetime_without_tzinfo.rs | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs index 8f46629e293ba..963a07d757110 100644 --- a/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs +++ b/crates/ruff/src/rules/flake8_datetimez/rules/call_datetime_without_tzinfo.rs @@ -9,6 +9,28 @@ use crate::checkers::ast::Checker; use super::helpers; +/// ## What it does +/// Checks for `datetime` instantiations that lack a `tzinfo` argument. +/// +/// ## Why is this bad? +/// `datetime` objects are "naive" by default, in that they do not include +/// timezone information. By providing a `tzinfo`, a `datetime` can be made +/// timezone "aware". "Naive" objects are easy to understand, but ignore some +/// aspects of reality, which can lead to subtle bugs. +/// +/// ## Example +/// ```python +/// import datetime +/// +/// datetime.datetime(2000, 1, 1, 0, 0, 0) +/// ``` +/// +/// Use instead: +/// ```python +/// import datetime +/// +/// datetime.datetime(2000, 1, 1, 0, 0, 0, tzinfo=datetime.UTC) +/// ``` #[violation] pub struct CallDatetimeWithoutTzinfo;