Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize the codebase #204

Merged
merged 10 commits into from
Feb 4, 2020
14 changes: 14 additions & 0 deletions src/objects/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,24 @@ impl PyModule {
/// Gets the module filename.
///
/// May fail if the module does not have a `__file__` attribute.
#[allow(deprecated)]
gracinet marked this conversation as resolved.
Show resolved Hide resolved
pub fn filename<'a>(&'a self, py: Python) -> PyResult<&'a str> {
unsafe { self.str_from_ptr(py, ffi::PyModule_GetFilename(self.0.as_ptr())) }
}

/// Gets the module filename object.
///
/// May fail if the module does not have a `__file__` attribute.
#[cfg(feature = "python3-sys")]
pub fn filename_object<'a>(&'a self, py: Python) -> PyResult<PyObject> {
let ptr = unsafe { ffi::PyModule_GetFilenameObject(self.0.as_ptr()) };
if ptr.is_null() {
Err(PyErr::fetch(py))
} else {
Ok(unsafe { PyObject::from_borrowed_ptr(py, ptr) })
}
}

/// Gets a member from the module.
/// This is equivalent to the Python expression: `getattr(module, name)`
pub fn get(&self, py: Python, name: &str) -> PyResult<PyObject> {
Expand Down