Skip to content

Commit 63ff262

Browse files
sollyuckodavidhewitt
authored andcommitted
fix typo DateType -> DateTimeType, fixes #3069
1 parent 48c0655 commit 63ff262

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

newsfragments/3071.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix isinstance for DateTime (was confused with Date).

src/types/datetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ pub struct PyDateTime(PyAny);
228228
pyobject_native_type!(
229229
PyDateTime,
230230
crate::ffi::PyDateTime_DateTime,
231-
*ensure_datetime_api(Python::assume_gil_acquired()).DateType,
231+
*ensure_datetime_api(Python::assume_gil_acquired()).DateTimeType,
232232
#module=Some("datetime"),
233233
#checkfunction=PyDateTime_Check
234234
);

tests/test_datetime.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#![cfg(not(Py_LIMITED_API))]
22

33
use pyo3::prelude::*;
4-
use pyo3::types::{timezone_utc, IntoPyDict};
4+
use pyo3::types::{timezone_utc, IntoPyDict, PyDate, PyDateTime, PyTime};
55
use pyo3_ffi::PyDateTime_IMPORT;
66

77
fn _get_subclasses<'p>(
@@ -61,6 +61,9 @@ fn test_date_check() {
6161
assert_check_exact!(PyDate_Check, PyDate_CheckExact, obj);
6262
assert_check_only!(PyDate_Check, PyDate_CheckExact, sub_obj);
6363
assert_check_only!(PyDate_Check, PyDate_CheckExact, sub_sub_obj);
64+
assert!(obj.is_instance_of::<PyDate>().unwrap());
65+
assert!(!obj.is_instance_of::<PyTime>().unwrap());
66+
assert!(!obj.is_instance_of::<PyDateTime>().unwrap());
6467
});
6568
}
6669

@@ -73,6 +76,9 @@ fn test_time_check() {
7376
assert_check_exact!(PyTime_Check, PyTime_CheckExact, obj);
7477
assert_check_only!(PyTime_Check, PyTime_CheckExact, sub_obj);
7578
assert_check_only!(PyTime_Check, PyTime_CheckExact, sub_sub_obj);
79+
assert!(!obj.is_instance_of::<PyDate>().unwrap());
80+
assert!(obj.is_instance_of::<PyTime>().unwrap());
81+
assert!(!obj.is_instance_of::<PyDateTime>().unwrap());
7682
});
7783
}
7884

@@ -88,6 +94,9 @@ fn test_datetime_check() {
8894
assert_check_exact!(PyDateTime_Check, PyDateTime_CheckExact, obj);
8995
assert_check_only!(PyDateTime_Check, PyDateTime_CheckExact, sub_obj);
9096
assert_check_only!(PyDateTime_Check, PyDateTime_CheckExact, sub_sub_obj);
97+
assert!(obj.is_instance_of::<PyDate>().unwrap());
98+
assert!(!obj.is_instance_of::<PyTime>().unwrap());
99+
assert!(obj.is_instance_of::<PyDateTime>().unwrap());
91100
});
92101
}
93102

0 commit comments

Comments
 (0)