Skip to content

Commit

Permalink
fix typo DateType -> DateTimeType, fixes #3069
Browse files Browse the repository at this point in the history
  • Loading branch information
sollyucko authored and adamreichold committed Mar 28, 2023
1 parent ba6261c commit 7e2f732
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions newsfragments/3071.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix isinstance for DateTime (was confused with Date).
2 changes: 1 addition & 1 deletion src/types/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
11 changes: 10 additions & 1 deletion tests/test_datetime.rs
Original file line number Diff line number Diff line change
@@ -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>(
Expand Down Expand Up @@ -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::<PyDate>().unwrap());
assert!(!obj.is_instance_of::<PyTime>().unwrap());
assert!(!obj.is_instance_of::<PyDateTime>().unwrap());
});
}

Expand All @@ -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::<PyDate>().unwrap());
assert!(obj.is_instance_of::<PyTime>().unwrap());
assert!(!obj.is_instance_of::<PyDateTime>().unwrap());
});
}

Expand All @@ -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::<PyDate>().unwrap());
assert!(!obj.is_instance_of::<PyTime>().unwrap());
assert!(obj.is_instance_of::<PyDateTime>().unwrap());
});
}

Expand Down

0 comments on commit 7e2f732

Please sign in to comment.