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

Add support for type hinting objects #4917

Merged
merged 11 commits into from
Feb 19, 2025
Prev Previous commit
Next Next commit
Handle errors in PyGenericAlias::new
IvanIsCoding committed Feb 19, 2025
commit 3c2ab624689f0b2a464a1022f58b847cda6e4385
11 changes: 6 additions & 5 deletions src/types/genericalias.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::err::PyResult;
use crate::ffi_ptr_ext::FfiPtrExt;
use crate::{ffi, types::any::PyAnyMethods, Bound, PyAny, Python};

@@ -27,11 +28,11 @@ impl PyGenericAlias {
py: Python<'py>,
origin: &Bound<'py, PyAny>,
args: &Bound<'py, PyAny>,
) -> Bound<'py, PyGenericAlias> {
) -> PyResult<Bound<'py, PyGenericAlias>> {
unsafe {
ffi::Py_GenericAlias(origin.as_ptr(), args.as_ptr())
.assume_owned(py)
.downcast_into_unchecked()
Ok(ffi::Py_GenericAlias(origin.as_ptr(), args.as_ptr())
.assume_owned_or_err(py)?
.downcast_into_unchecked())
}
}
}
@@ -62,7 +63,7 @@ mod tests {
.eval(ffi::c_str!("(int,)"), None, None)
.unwrap()
.into_bound();
let generic_alias = PyGenericAlias::new(py, &cls, &key);
let generic_alias = PyGenericAlias::new(py, &cls, &key).unwrap();

assert!(generic_alias.eq(list_int).unwrap());
})
Loading