Fix examples with the new #[new] API

This commit is contained in:
kngwyu 2019-12-22 23:59:28 +09:00
parent e2dc843de5
commit acb1120c55
7 changed files with 16 additions and 15 deletions

View File

@ -9,8 +9,8 @@ struct BytesExtractor {}
#[pymethods]
impl BytesExtractor {
#[new]
pub fn __new__(obj: &PyRawObject) {
obj.init({ BytesExtractor {} });
pub fn __new__() -> Self {
BytesExtractor {}
}
pub fn from_bytes(&mut self, bytes: &PyBytes) -> PyResult<usize> {

View File

@ -195,8 +195,8 @@ pub struct TzClass {}
#[pymethods]
impl TzClass {
#[new]
fn new(obj: &PyRawObject) {
obj.init(TzClass {})
fn new() -> Self {
TzClass {}
}
fn utcoffset<'p>(&self, py: Python<'p>, _dt: &PyDateTime) -> PyResult<&'p PyDelta> {

View File

@ -16,8 +16,8 @@ pub struct DictSize {
#[pymethods]
impl DictSize {
#[new]
fn new(obj: &PyRawObject, expected: u32) {
obj.init(DictSize { expected })
fn new(expected: u32) -> Self {
DictSize { expected }
}
fn iter_dict(&mut self, _py: Python<'_>, dict: &PyDict) -> PyResult<u32> {

View File

@ -13,10 +13,10 @@ pub struct ModClass {
#[pymethods]
impl ModClass {
#[new]
fn new(obj: &PyRawObject) {
obj.init(ModClass {
fn new() -> Self {
ModClass {
_somefield: String::from("contents"),
})
}
}
fn noop(&self, x: usize) -> usize {

View File

@ -8,8 +8,8 @@ pub struct Subclassable {}
#[pymethods]
impl Subclassable {
#[new]
fn new(obj: &PyRawObject) {
obj.init(Subclassable {});
fn new() -> Self {
Subclassable {}
}
}

View File

@ -16,10 +16,10 @@ struct WordCounter {
#[pymethods]
impl WordCounter {
#[new]
fn new(obj: &PyRawObject, path: String) {
obj.init(WordCounter {
fn new(path: String) -> Self {
WordCounter {
path: PathBuf::from(path),
});
}
}
/// Searches for the word, parallelized by rayon

View File

@ -318,8 +318,9 @@ impl PyTimeAccess for PyTime {
///
/// This is an abstract base class and should not be constructed directly.
pub struct PyTzInfo(PyObject, Unsendable);
pyobject_native_var_type!(
pyobject_native_type!(
PyTzInfo,
crate::ffi::PyObject,
*PyDateTimeAPI.TZInfoType,
Some("datetime"),
PyTZInfo_Check