Merge branch 'master' of github.com:PyO3/pyo3

This commit is contained in:
Nikolay Kim 2018-01-17 08:10:01 -08:00
commit 35e91a5cd1
5 changed files with 16 additions and 15 deletions

View File

@ -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);

View File

@ -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<T>` 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.

View File

@ -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.

1
rust-toolchain Normal file
View File

@ -0,0 +1 @@
nightly

View File

@ -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<A, K>(&self, name: &str, args: A, kwargs: K) -> PyResult<&PyObjectRef>
where A: IntoPyTuple,