Skip to content

Porting to 0.9 after #770 #785

@birkenfeld

Description

@birkenfeld

Two points (Using pyo3 master branch from today, Rust 1.43.0 nightly from 2020-02-22), both should be noted in the release notes.

first

After #770, I've noticed that I can't use &Class and &mut Class as method arguments anymore, where Class is a #[pyclass] annotated struct. Instead, it has to be &PyCell<Class> (I assume, at least that works).

second

Furthermore, now I can't cast PyAny and PyObject objects referring to a Class to Rust references anymore. Previously I used PyAny::downcast_ref (now downcast) and PyObject::cast_as. The error is in both cases the same, i.e.

error[E0277]: the trait bound `ast::segments::OtherSegment: pyo3::instance::PyNativeType` is not satisfied
   --> src/ast/mod.rs:405:37
    |
405 |         } else if let Ok(seg) = seg.cast_as::<OtherSegment>(py) {
    |                                     ^^^^^^^ the trait `pyo3::instance::PyNativeType` is not implemented for `ast::segments::OtherSegment`
    |
    = note: required because of the requirements on the impl of `pyo3::conversion::PyTryFrom<'_>` for `ast::segments::OtherSegment`

One way I found to fix this was to use seg.extract::<&PyCell<OtherSegment>>.borrow().
This is quite cumbersome -- is there/could there be a shortcut?

Of course this should also be noted in the release notes.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions