From 63ff26293fb90869abfeafc97dc321caec672ad7 Mon Sep 17 00:00:00 2001 From: Solomon Ucko Date: Mon, 27 Mar 2023 14:30:09 -0400 Subject: [PATCH] fix typo DateType -> DateTimeType, fixes #3069 --- newsfragments/3071.fixed.md | 1 + src/types/datetime.rs | 2 +- tests/test_datetime.rs | 11 ++++++++++- 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 newsfragments/3071.fixed.md diff --git a/newsfragments/3071.fixed.md b/newsfragments/3071.fixed.md new file mode 100644 index 00000000000..50953c6f1e5 --- /dev/null +++ b/newsfragments/3071.fixed.md @@ -0,0 +1 @@ +Fix isinstance for DateTime (was confused with Date). diff --git a/src/types/datetime.rs b/src/types/datetime.rs index 85860728568..2c995356e2c 100644 --- a/src/types/datetime.rs +++ b/src/types/datetime.rs @@ -228,7 +228,7 @@ pub struct PyDateTime(PyAny); pyobject_native_type!( PyDateTime, crate::ffi::PyDateTime_DateTime, - *ensure_datetime_api(Python::assume_gil_acquired()).DateType, + *ensure_datetime_api(Python::assume_gil_acquired()).DateTimeType, #module=Some("datetime"), #checkfunction=PyDateTime_Check ); diff --git a/tests/test_datetime.rs b/tests/test_datetime.rs index bc5299351a3..34c2b18d3dd 100644 --- a/tests/test_datetime.rs +++ b/tests/test_datetime.rs @@ -1,7 +1,7 @@ #![cfg(not(Py_LIMITED_API))] use pyo3::prelude::*; -use pyo3::types::{timezone_utc, IntoPyDict}; +use pyo3::types::{timezone_utc, IntoPyDict, PyDate, PyDateTime, PyTime}; use pyo3_ffi::PyDateTime_IMPORT; fn _get_subclasses<'p>( @@ -61,6 +61,9 @@ fn test_date_check() { assert_check_exact!(PyDate_Check, PyDate_CheckExact, obj); assert_check_only!(PyDate_Check, PyDate_CheckExact, sub_obj); assert_check_only!(PyDate_Check, PyDate_CheckExact, sub_sub_obj); + assert!(obj.is_instance_of::().unwrap()); + assert!(!obj.is_instance_of::().unwrap()); + assert!(!obj.is_instance_of::().unwrap()); }); } @@ -73,6 +76,9 @@ fn test_time_check() { assert_check_exact!(PyTime_Check, PyTime_CheckExact, obj); assert_check_only!(PyTime_Check, PyTime_CheckExact, sub_obj); assert_check_only!(PyTime_Check, PyTime_CheckExact, sub_sub_obj); + assert!(!obj.is_instance_of::().unwrap()); + assert!(obj.is_instance_of::().unwrap()); + assert!(!obj.is_instance_of::().unwrap()); }); } @@ -88,6 +94,9 @@ fn test_datetime_check() { assert_check_exact!(PyDateTime_Check, PyDateTime_CheckExact, obj); assert_check_only!(PyDateTime_Check, PyDateTime_CheckExact, sub_obj); assert_check_only!(PyDateTime_Check, PyDateTime_CheckExact, sub_sub_obj); + assert!(obj.is_instance_of::().unwrap()); + assert!(!obj.is_instance_of::().unwrap()); + assert!(obj.is_instance_of::().unwrap()); }); }