rust-cpython icon indicating copy to clipboard operation
rust-cpython copied to clipboard

Flexible parameter lists

Open dgrunwald opened this issue 9 years ago • 1 comments

Add support for:

  • [x] Optional parameters
  • [ ] *args
  • [ ] **kwargs

dgrunwald avatar Mar 07 '16 20:03 dgrunwald

Did you had the time to implement this? The documentation say so, and parameters with or without explicit type works.

But trying to use default values gives me errors about unexpected value:

#[macro_use] extern crate cpython;
use cpython::{Python, PyResult};

py_class!(class MyType |py| {
    data number: i32;
    def __new__(_cls, arg: i32) -> PyResult<MyType> {
        MyType::create_instance(py, arg)
    }
    def foo(&self, a, b: i32 = 8) -> PyResult<PyObject> {
    // ===> Error: no rules expected the token `8`at line 62 col 44 in <cpython macros>
        println!("{} {}", a, b);
        Ok(py.None())
    }
});

I tried to read the code to see where this could come from, but my macro-fu is not that good ...

Luthaf avatar Oct 14 '16 10:10 Luthaf