Rename the `base` option in the `pyclass` macro to `extends`
"extends" is intuitive for people with java or ES6 experience, and it also aligns pyo3 with wasm-bindgen (see https://github.com/rustwasm/rfcs/pull/2)
This commit is contained in:
parent
eb613c64d9
commit
dbd74401eb
|
@ -5,6 +5,7 @@
|
|||
* Upgraded to syn 0.14 which means much better error messages :tada:
|
||||
* 128 bit integer support by [kngwyu](https://github.com/kngwyu) ([#137](https://github.com/PyO3/pyo3/pull/173))
|
||||
* Added `py` prefixes to the proc macros and moved them into the root module. You should just use the plain proc macros, i.e. `#[pyclass]`, `#[pymethods]`, `#[pyproto]`, `#[pyfunction]` and `#[pymodinit]`. This is important because `proc_macro_path_invoc` isn't going to be stabilized soon.
|
||||
* Renamed the `base` option in the `pyclass` macro to `extends`.
|
||||
* `#[pymodinit]` uses the function name as module name, unless the name is overrriden with `#[pymodinit(name)]`
|
||||
* The guide is now properly versioned.
|
||||
* A few internal macros became part of the public api ([#155](https://github.com/PyO3/pyo3/pull/155), [#186](https://github.com/PyO3/pyo3/pull/186))
|
||||
|
|
|
@ -33,7 +33,7 @@ so that they can benefit from a freelist. `XXX` is a number of items for free li
|
|||
participate in python garbage collector. If a custom class contains references to other
|
||||
python object that can be collected, the `PyGCProtocol` trait has to be implemented.
|
||||
* `weakref` - adds support for python weak references
|
||||
* `base=BaseType` - use a custom base class. The base BaseType must implement `PyTypeInfo`.
|
||||
* `extends=BaseType` - use a custom base class. The base BaseType must implement `PyTypeInfo`.
|
||||
* `subclass` - Allows Python classes to inherit from this class
|
||||
* `dict` - adds `__dict__` support, the instances of this type have a dictionary containing instance variables. (Incomplete, see [#123](https://github.com/PyO3/pyo3/issues/123))
|
||||
|
||||
|
@ -115,7 +115,7 @@ impl BaseClass {
|
|||
}
|
||||
}
|
||||
|
||||
#[pyclass(base=BaseClass)]
|
||||
#[pyclass(extends=BaseClass)]
|
||||
struct SubClass {
|
||||
val2: usize,
|
||||
token: PyToken,
|
||||
|
|
|
@ -180,6 +180,7 @@ mod test {
|
|||
|
||||
use args::{parse_arguments, Argument};
|
||||
use syn;
|
||||
use proc_macro::TokenStream;
|
||||
|
||||
fn items(s: TokenStream) -> Vec<syn::NestedMeta> {
|
||||
let dummy: syn::ItemFn = parse_quote!{#s fn dummy() {}};
|
||||
|
|
|
@ -17,11 +17,10 @@ pub fn py3_init(fnname: &syn::Ident, name: &syn::Ident, doc: syn::Lit) -> TokenS
|
|||
quote! {
|
||||
#[no_mangle]
|
||||
#[allow(non_snake_case)]
|
||||
#[doc(hidden)]
|
||||
/// This autogenerated function is called by the python interpreter when importing
|
||||
/// the module.
|
||||
pub unsafe extern "C" fn #cb_name() -> *mut ::pyo3::ffi::PyObject {
|
||||
use ::pyo3::{IntoPyPointer, ObjectProtocol};
|
||||
|
||||
::pyo3::init_once();
|
||||
|
||||
static mut MODULE_DEF: ::pyo3::ffi::PyModuleDef = ::pyo3::ffi::PyModuleDef_INIT;
|
||||
|
@ -48,7 +47,7 @@ pub fn py3_init(fnname: &syn::Ident, name: &syn::Ident, doc: syn::Lit) -> TokenS
|
|||
};
|
||||
_module.add("__doc__", #doc).expect("Failed to add doc for module");
|
||||
match #fnname(_py, _module) {
|
||||
Ok(_) => _module.into_ptr(),
|
||||
Ok(_) => ::pyo3::IntoPyPointer::into_ptr(_module),
|
||||
Err(e) => {
|
||||
e.restore(_py);
|
||||
::std::ptr::null_mut()
|
||||
|
|
|
@ -445,7 +445,7 @@ fn parse_attribute(
|
|||
}
|
||||
_ => println!("Wrong 'name' format: {:?}", *ass.right),
|
||||
},
|
||||
"base" => match *ass.right {
|
||||
"extends" => match *ass.right {
|
||||
syn::Expr::Path(ref exp) => {
|
||||
base = syn::TypePath {
|
||||
path: exp.path.clone(),
|
||||
|
|
|
@ -231,7 +231,7 @@ impl Drop for BaseClassWithDrop {
|
|||
}
|
||||
}
|
||||
|
||||
#[pyclass(base=BaseClassWithDrop)]
|
||||
#[pyclass(extends=BaseClassWithDrop)]
|
||||
struct SubClassWithDrop {
|
||||
token: PyToken,
|
||||
data: Option<Arc<AtomicBool>>,
|
||||
|
|
|
@ -43,7 +43,7 @@ impl BaseClass {
|
|||
}
|
||||
}
|
||||
|
||||
#[pyclass(base=BaseClass)]
|
||||
#[pyclass(extends=BaseClass)]
|
||||
struct SubClass {
|
||||
#[prop(get)]
|
||||
val2: usize,
|
||||
|
|
Loading…
Reference in New Issue