Skip to content

Commit dbd7440

Browse files
committed
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 rustwasm/rfcs#2)
1 parent eb613c6 commit dbd7440

File tree

7 files changed

+9
-8
lines changed

7 files changed

+9
-8
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Upgraded to syn 0.14 which means much better error messages :tada:
66
* 128 bit integer support by [kngwyu](https://github.com/kngwyu) ([#137](https://github.com/PyO3/pyo3/pull/173))
77
* 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.
8+
* Renamed the `base` option in the `pyclass` macro to `extends`.
89
* `#[pymodinit]` uses the function name as module name, unless the name is overrriden with `#[pymodinit(name)]`
910
* The guide is now properly versioned.
1011
* 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))

guide/src/class.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ so that they can benefit from a freelist. `XXX` is a number of items for free li
3333
participate in python garbage collector. If a custom class contains references to other
3434
python object that can be collected, the `PyGCProtocol` trait has to be implemented.
3535
* `weakref` - adds support for python weak references
36-
* `base=BaseType` - use a custom base class. The base BaseType must implement `PyTypeInfo`.
36+
* `extends=BaseType` - use a custom base class. The base BaseType must implement `PyTypeInfo`.
3737
* `subclass` - Allows Python classes to inherit from this class
3838
* `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))
3939

@@ -115,7 +115,7 @@ impl BaseClass {
115115
}
116116
}
117117

118-
#[pyclass(base=BaseClass)]
118+
#[pyclass(extends=BaseClass)]
119119
struct SubClass {
120120
val2: usize,
121121
token: PyToken,

pyo3-derive-backend/src/args.rs

+1
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ mod test {
180180

181181
use args::{parse_arguments, Argument};
182182
use syn;
183+
use proc_macro::TokenStream;
183184

184185
fn items(s: TokenStream) -> Vec<syn::NestedMeta> {
185186
let dummy: syn::ItemFn = parse_quote!{#s fn dummy() {}};

pyo3-derive-backend/src/module.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ pub fn py3_init(fnname: &syn::Ident, name: &syn::Ident, doc: syn::Lit) -> TokenS
1717
quote! {
1818
#[no_mangle]
1919
#[allow(non_snake_case)]
20+
#[doc(hidden)]
2021
/// This autogenerated function is called by the python interpreter when importing
2122
/// the module.
2223
pub unsafe extern "C" fn #cb_name() -> *mut ::pyo3::ffi::PyObject {
23-
use ::pyo3::{IntoPyPointer, ObjectProtocol};
24-
2524
::pyo3::init_once();
2625

2726
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
4847
};
4948
_module.add("__doc__", #doc).expect("Failed to add doc for module");
5049
match #fnname(_py, _module) {
51-
Ok(_) => _module.into_ptr(),
50+
Ok(_) => ::pyo3::IntoPyPointer::into_ptr(_module),
5251
Err(e) => {
5352
e.restore(_py);
5453
::std::ptr::null_mut()

pyo3-derive-backend/src/py_class.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ fn parse_attribute(
445445
}
446446
_ => println!("Wrong 'name' format: {:?}", *ass.right),
447447
},
448-
"base" => match *ass.right {
448+
"extends" => match *ass.right {
449449
syn::Expr::Path(ref exp) => {
450450
base = syn::TypePath {
451451
path: exp.path.clone(),

tests/test_gc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl Drop for BaseClassWithDrop {
231231
}
232232
}
233233

234-
#[pyclass(base=BaseClassWithDrop)]
234+
#[pyclass(extends=BaseClassWithDrop)]
235235
struct SubClassWithDrop {
236236
token: PyToken,
237237
data: Option<Arc<AtomicBool>>,

tests/test_inheritance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl BaseClass {
4343
}
4444
}
4545

46-
#[pyclass(base=BaseClass)]
46+
#[pyclass(extends=BaseClass)]
4747
struct SubClass {
4848
#[prop(get)]
4949
val2: usize,

0 commit comments

Comments
 (0)