diff --git a/examples/rustapi_module/src/lib.rs b/examples/rustapi_module/src/lib.rs index a3652764..84f14e8c 100644 --- a/examples/rustapi_module/src/lib.rs +++ b/examples/rustapi_module/src/lib.rs @@ -176,16 +176,7 @@ fn get_datetime_tuple_fold(py: Python, dt: &PyDateTime) -> Py { #[pyfunction] fn datetime_from_timestamp(py: Python, ts: f64, tz: Option<&PyTzInfo>) -> PyResult> { - let timestamp: PyObject = ts.to_object(py); - let tzi: PyObject = match tz { - Some(t) => t.to_object(py), - None => py.None(), - }; - - let args = PyTuple::new(py, &[timestamp, tzi]); - let kwargs = PyDict::new(py); - - PyDateTime::from_timestamp(py, &args.to_object(py), &kwargs.to_object(py)) + PyDateTime::from_timestamp(py, ts, tz) } #[pyfunction] diff --git a/src/types/datetime.rs b/src/types/datetime.rs index 912c90d7..a4cc39cb 100644 --- a/src/types/datetime.rs +++ b/src/types/datetime.rs @@ -1,7 +1,10 @@ +use conversion::ToPyObject; use err::PyResult; use ffi; use ffi::PyDateTimeAPI; use ffi::{PyDateTime_Check, PyDateTime_DateTimeType}; +#[cfg(Py_3_6)] +use ffi::{PyDateTime_DATE_GET_FOLD, PyDateTime_TIME_GET_FOLD}; use ffi::{ PyDateTime_DATE_GET_HOUR, PyDateTime_DATE_GET_MICROSECOND, PyDateTime_DATE_GET_MINUTE, PyDateTime_DATE_GET_SECOND, @@ -18,14 +21,11 @@ use ffi::{ }; use ffi::{PyDateTime_TZInfoType, PyTZInfo_Check}; use ffi::{PyDateTime_TimeType, PyTime_Check}; -use object::PyObject; -use std::os::raw::c_int; - -#[cfg(Py_3_6)] -use ffi::{PyDateTime_DATE_GET_FOLD, PyDateTime_TIME_GET_FOLD}; - use instance::Py; +use object::PyObject; use python::{Python, ToPyPointer}; +use std::os::raw::c_int; +use std::ptr; use types::PyTuple; // Traits @@ -125,14 +125,23 @@ impl PyDateTime { pub fn from_timestamp( py: Python, - args: &PyObject, - kwargs: &PyObject, + timestamp: f64, + time_zone_info: Option<&PyTzInfo>, ) -> PyResult> { + let timestamp: PyObject = timestamp.to_object(py); + + let time_zone_info: PyObject = match time_zone_info { + Some(time_zone_info) => time_zone_info.to_object(py), + None => py.None(), + }; + + let args = PyTuple::new(py, &[timestamp, time_zone_info]); + unsafe { let ptr = (PyDateTimeAPI.DateTime_FromTimestamp)( PyDateTimeAPI.DateTimeType, args.as_ptr(), - kwargs.as_ptr(), + ptr::null_mut(), ); Py::from_owned_ptr_or_err(py, ptr) } diff --git a/src/types/dict.rs b/src/types/dict.rs index 76e518d1..bc5d9ad9 100644 --- a/src/types/dict.rs +++ b/src/types/dict.rs @@ -5,7 +5,7 @@ use err::{self, PyErr, PyResult}; use ffi; use instance::PyObjectWithToken; use object::PyObject; -use python::{Python, ToPyPointer, IntoPyPointer}; +use python::{IntoPyPointer, Python, ToPyPointer}; use std; use std::{cmp, collections, hash, mem}; use types::{PyList, PyObjectRef}; @@ -277,7 +277,7 @@ mod test { use python::Python; use std::collections::{BTreeMap, HashMap}; use types::dict::IntoPyDict; - use types::{PyDict, PyTuple, PyList}; + use types::{PyDict, PyList, PyTuple}; use ObjectProtocol; #[test]