fix typo DateType -> DateTimeType, fixes #3069

This commit is contained in:
Solomon Ucko 2023-03-27 14:30:09 -04:00 committed by Adam Reichold
parent ba6261c8e7
commit 7e2f732d7a
3 changed files with 12 additions and 2 deletions

View File

@ -0,0 +1 @@
Fix isinstance for DateTime (was confused with Date).

View File

@ -228,7 +228,7 @@ pub struct PyDateTime(PyAny);
pyobject_native_type!( pyobject_native_type!(
PyDateTime, PyDateTime,
crate::ffi::PyDateTime_DateTime, crate::ffi::PyDateTime_DateTime,
*ensure_datetime_api(Python::assume_gil_acquired()).DateType, *ensure_datetime_api(Python::assume_gil_acquired()).DateTimeType,
#module=Some("datetime"), #module=Some("datetime"),
#checkfunction=PyDateTime_Check #checkfunction=PyDateTime_Check
); );

View File

@ -1,7 +1,7 @@
#![cfg(not(Py_LIMITED_API))] #![cfg(not(Py_LIMITED_API))]
use pyo3::prelude::*; use pyo3::prelude::*;
use pyo3::types::{timezone_utc, IntoPyDict}; use pyo3::types::{timezone_utc, IntoPyDict, PyDate, PyDateTime, PyTime};
use pyo3_ffi::PyDateTime_IMPORT; use pyo3_ffi::PyDateTime_IMPORT;
fn _get_subclasses<'p>( fn _get_subclasses<'p>(
@ -61,6 +61,9 @@ fn test_date_check() {
assert_check_exact!(PyDate_Check, PyDate_CheckExact, obj); 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_obj);
assert_check_only!(PyDate_Check, PyDate_CheckExact, sub_sub_obj); assert_check_only!(PyDate_Check, PyDate_CheckExact, sub_sub_obj);
assert!(obj.is_instance_of::<PyDate>().unwrap());
assert!(!obj.is_instance_of::<PyTime>().unwrap());
assert!(!obj.is_instance_of::<PyDateTime>().unwrap());
}); });
} }
@ -73,6 +76,9 @@ fn test_time_check() {
assert_check_exact!(PyTime_Check, PyTime_CheckExact, obj); 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_obj);
assert_check_only!(PyTime_Check, PyTime_CheckExact, sub_sub_obj); assert_check_only!(PyTime_Check, PyTime_CheckExact, sub_sub_obj);
assert!(!obj.is_instance_of::<PyDate>().unwrap());
assert!(obj.is_instance_of::<PyTime>().unwrap());
assert!(!obj.is_instance_of::<PyDateTime>().unwrap());
}); });
} }
@ -88,6 +94,9 @@ fn test_datetime_check() {
assert_check_exact!(PyDateTime_Check, PyDateTime_CheckExact, obj); 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_obj);
assert_check_only!(PyDateTime_Check, PyDateTime_CheckExact, sub_sub_obj); assert_check_only!(PyDateTime_Check, PyDateTime_CheckExact, sub_sub_obj);
assert!(obj.is_instance_of::<PyDate>().unwrap());
assert!(!obj.is_instance_of::<PyTime>().unwrap());
assert!(obj.is_instance_of::<PyDateTime>().unwrap());
}); });
} }