-
Notifications
You must be signed in to change notification settings - Fork 792
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
None, Ellipsis, and NotImplemented
- Loading branch information
Showing
6 changed files
with
83 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::{ffi, PyAny, Python}; | ||
|
||
/// Represents the Python `Ellipsis` object. | ||
#[repr(transparent)] | ||
pub struct PyEllipsis(PyAny); | ||
|
||
pyobject_native_type!( | ||
PyEllipsis, | ||
ffi::PyObject, | ||
pyobject_native_static_type_object!(ffi::PyEllipsis_Type) | ||
); | ||
|
||
impl PyEllipsis { | ||
/// Returns the `Ellipsis` object. | ||
#[inline] | ||
pub fn get(py: Python<'_>) -> &PyEllipsis { | ||
unsafe { py.from_borrowed_ptr(ffi::Py_Ellipsis()) } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
use crate::{ffi, IntoPy, PyAny, PyObject, Python, ToPyObject}; | ||
|
||
/// Represents the Python `None` object. | ||
#[repr(transparent)] | ||
pub struct PyNone(PyAny); | ||
|
||
pyobject_native_type!( | ||
PyNone, | ||
ffi::PyObject, | ||
pyobject_native_static_type_object!(ffi::_PyNone_Type) | ||
); | ||
|
||
impl PyNone { | ||
/// Returns the `None` object. | ||
#[inline] | ||
pub fn get(py: Python<'_>) -> &PyNone { | ||
unsafe { py.from_borrowed_ptr(ffi::Py_None()) } | ||
} | ||
} | ||
|
||
/// `()` is converted to Python `None`. | ||
impl ToPyObject for () { | ||
fn to_object(&self, py: Python<'_>) -> PyObject { | ||
PyNone::get(py).into() | ||
} | ||
} | ||
|
||
impl IntoPy<PyObject> for () { | ||
#[inline] | ||
fn into_py(self, py: Python<'_>) -> PyObject { | ||
PyNone::get(py).into() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
use crate::{ffi, PyAny, Python}; | ||
|
||
/// Represents the Python `NotImplemented` object. | ||
#[repr(transparent)] | ||
pub struct PyNotImplemented(PyAny); | ||
|
||
pyobject_native_type!( | ||
PyNotImplemented, | ||
ffi::PyObject, | ||
pyobject_native_static_type_object!(ffi::_PyNotImplemented_Type) | ||
); | ||
|
||
impl PyNotImplemented { | ||
/// Returns the `NotImplemented` object. | ||
#[inline] | ||
pub fn get(py: Python<'_>) -> &PyNotImplemented { | ||
unsafe { py.from_borrowed_ptr(ffi::Py_NotImplemented()) } | ||
} | ||
} |