Skip to content

Commit

Permalink
use type_check and type_check_exact
Browse files Browse the repository at this point in the history
  • Loading branch information
davidhewitt committed Nov 15, 2020
1 parent 4bcc673 commit 521db82
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ where
fn try_from<V: Into<&'v PyAny>>(value: V) -> Result<&'v Self, PyDowncastError<'v>> {
let value = value.into();
unsafe {
if T::check(value) {
if T::type_check(value) {
Ok(Self::try_from_unchecked(value))
} else {
Err(PyDowncastError::new(value, T::NAME))
Expand All @@ -337,7 +337,7 @@ where
fn try_from_exact<V: Into<&'v PyAny>>(value: V) -> Result<&'v Self, PyDowncastError<'v>> {
let value = value.into();
unsafe {
if T::check_exact(value) {
if T::type_check_exact(value) {
Ok(Self::try_from_unchecked(value))
} else {
Err(PyDowncastError::new(value, T::NAME))
Expand All @@ -358,7 +358,7 @@ where
fn try_from<V: Into<&'v PyAny>>(value: V) -> Result<&'v Self, PyDowncastError<'v>> {
let value = value.into();
unsafe {
if T::check(value) {
if T::type_check(value) {
Ok(Self::try_from_unchecked(value))
} else {
Err(PyDowncastError::new(value, T::NAME))
Expand All @@ -368,7 +368,7 @@ where
fn try_from_exact<V: Into<&'v PyAny>>(value: V) -> Result<&'v Self, PyDowncastError<'v>> {
let value = value.into();
unsafe {
if T::check_exact(value) {
if T::type_check_exact(value) {
Ok(Self::try_from_unchecked(value))
} else {
Err(PyDowncastError::new(value, T::NAME))
Expand Down
4 changes: 2 additions & 2 deletions src/type_object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ pub unsafe trait PyTypeInfo: Sized {
fn type_object_raw(py: Python) -> *mut ffi::PyTypeObject;

/// Checks if `object` is an instance of this type or a subclass of this type.
fn check(object: &PyAny) -> bool {
fn type_check(object: &PyAny) -> bool {
unsafe { ffi::PyObject_TypeCheck(object.as_ptr(), Self::type_object_raw(object.py())) != 0 }
}

/// Checks if `object` is an instance of this type.
fn check_exact(object: &PyAny) -> bool {
fn type_check_exact(object: &PyAny) -> bool {
unsafe { ffi::Py_TYPE(object.as_ptr()) == Self::type_object_raw(object.py()) }
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ macro_rules! pyobject_native_type_convert(
}

#[allow(unused_unsafe)]
fn check(ptr: &$crate::PyAny) -> bool {
fn type_check(ptr: &$crate::PyAny) -> bool {
use $crate::AsPyPointer;
unsafe { $checkfunction(ptr.as_ptr()) > 0 }
}
Expand Down

0 comments on commit 521db82

Please sign in to comment.