From 4b26edfa09d4f8a94e5b130c8be608da41cbc9b4 Mon Sep 17 00:00:00 2001 From: Guanqun Lu Date: Wed, 27 Dec 2017 18:35:49 +0800 Subject: [PATCH 1/4] display the required version and current version in error message --- build.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.rs b/build.rs index a4a29a6c..2ffe199a 100644 --- a/build.rs +++ b/build.rs @@ -357,7 +357,7 @@ fn configure_from_path(expected_version: &PythonVersion) -> Result<(String, Stri } if let Some(minor) = some_minor { if minor < PY3_MIN_MINOR { - return Err(format!("Python 3 min version is 3.{}", minor)) + return Err(format!("Python 3 required version is 3.{}, current version is 3.{}", PY3_MIN_MINOR, minor)) } for i in 5..(minor+1) { println!("cargo:rustc-cfg=Py_3_{}", i); From 4bc079f61998cf752aa6d01411d8a66130849ce7 Mon Sep 17 00:00:00 2001 From: Guanqun Lu Date: Wed, 27 Dec 2017 22:11:18 +0800 Subject: [PATCH 2/4] typo fix --- src/objectprotocol.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/objectprotocol.rs b/src/objectprotocol.rs index e51dd757..b50eaed5 100644 --- a/src/objectprotocol.rs +++ b/src/objectprotocol.rs @@ -97,7 +97,7 @@ pub trait ObjectProtocol { /// let obj = SomePyObject::new(); /// let args = (arg1, arg2, arg3); /// let kwargs = ((key1, value1), (key2, value2)); - /// let pid = obj.call_mwthod("do_something", args, kwargs); + /// let pid = obj.call_method("do_something", args, kwargs); /// ``` fn call_method(&self, name: &str, args: A, kwargs: K) -> PyResult<&PyObjectRef> where A: IntoPyTuple, From cd17b41b886c4e81696203b28b6c67bb296befaa Mon Sep 17 00:00:00 2001 From: Guanqun Lu Date: Wed, 27 Dec 2017 22:36:13 +0800 Subject: [PATCH 3/4] add a rust-toolchain file in the repo to indicate the toolchain used --- rust-toolchain | 1 + 1 file changed, 1 insertion(+) create mode 100644 rust-toolchain diff --git a/rust-toolchain b/rust-toolchain new file mode 100644 index 00000000..07ade694 --- /dev/null +++ b/rust-toolchain @@ -0,0 +1 @@ +nightly \ No newline at end of file From 81f31153aaefd2c193bb2e1c6697332ad692f095 Mon Sep 17 00:00:00 2001 From: Guanqun Lu Date: Wed, 27 Dec 2017 23:10:19 +0800 Subject: [PATCH 4/4] doc fixes --- guide/src/class.md | 24 ++++++++++++------------ guide/src/overview.md | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/guide/src/class.md b/guide/src/class.md index 4d3e39cc..b7e4bb8b 100644 --- a/guide/src/class.md +++ b/guide/src/class.md @@ -72,7 +72,7 @@ To declare constructor, you need to define class method and annotate it with `#[ attribute. Only python `__new__` method can be specified, `__init__` is not available. ```rust -#[py::method] +#[py::methods] impl MyClass { #[new] @@ -115,7 +115,7 @@ struct BaseClass { val1: usize } -#[py::class] +#[py::methods] impl BaseClass { #[new] fn __new__(obj: &PyRawObject) -> PyResult<()> { @@ -132,7 +132,7 @@ struct SubClass { val2: usize } -#[py::class] +#[py::methods] impl SubClass { #[new] fn __new__(obj: &PyRawObject) -> PyResult<()> { @@ -153,7 +153,7 @@ base class. ## Object properties Descriptor methods can be defined in -`#[methods]` `impl` block only and has to be annotated with `#[getter]` or `[setter]` +`#[py::methods]` `impl` block only and has to be annotated with `#[getter]` or `[setter]` attributes. i.e. ```rust @@ -252,7 +252,7 @@ impl MyClass { Calls to this methods protected by `GIL`, `&self` or `&mut self` can be used. The return type must be `PyResult` for some `T` that implements `IntoPyObject`. -`Python` parameter can be spefieid as part of method signature, in this case `py` argument +`Python` parameter can be specified as part of method signature, in this case `py` argument get injected by method wrapper. i.e ```rust @@ -311,7 +311,7 @@ impl MyClass { ## Callable object To specify custom `__call__` method for custom class, call method needs to be annotated -with `#[call]` attribute. Arguments of the method are speficied same as for instance method. +with `#[call]` attribute. Arguments of the method are specified same as for instance method. ```rust #[py::methods] @@ -331,19 +331,19 @@ impl MyClass { By default pyo3 library uses function signature to determine which arguments are required. Then it scans incoming `args` parameter and then incoming `kwargs` parameter. If it can not find all required parameters, it raises `TypeError` exception. -It is possible to override default bahavior with `#[args(...)]` attribute. `args` attribute +It is possible to override default behavior with `#[args(...)]` attribute. `args` attribute accept comma separated list of parameters in form `attr_name="default value"`. Each parameter has to match method parameter by name. Each parameter could one of following type: - * "\*": var arguments separator, each parameter defined after "*" is keyword only paramters. - coresponds to python's `def meth(*, arg1.., arg2=..)` - * args="\*": "args" is var args, coresponds to python's `def meth(*args)`. Type of `args` + * "\*": var arguments separator, each parameter defined after "*" is keyword only parameters. + corresponds to python's `def meth(*, arg1.., arg2=..)` + * args="\*": "args" is var args, corresponds to python's `def meth(*args)`. Type of `args` parameter has to be `&PyTuple`. - * kwargs="\*\*": "kwargs" is kwyword arguments, coresponds to python's `def meth(**kwargs)`. + * kwargs="\*\*": "kwargs" is kwyword arguments, corresponds to python's `def meth(**kwargs)`. Type of `kwargs` parameter has to be `Option<&PyDict>`. - * arg="Value": arguments with default value. coresponds to python's `def meth(arg=Value)`. + * arg="Value": arguments with default value. corresponds to python's `def meth(arg=Value)`. if `arg` argument is defined after var arguments it is treated as keyword argument. Note that `Value` has to be valid rust code, pyo3 just inserts it into generated code unmodified. diff --git a/guide/src/overview.md b/guide/src/overview.md index db2be6e2..d141be1f 100644 --- a/guide/src/overview.md +++ b/guide/src/overview.md @@ -126,7 +126,7 @@ by acquiring the GIL, and have to pass it into some operations that call into th PyO3 library provides wrappers for python native objects. Ownership of python objects are disallowed because any access to python runtime has to be protected by GIL. -All apis are available through references. Lifetimes of python object's refereces are +All apis are available through references. Lifetimes of python object's references are bound to GIL lifetime. There are two types of pointers that could be stored on rust structs.