I'm trying to make a file writing interface be its own context manager with PyO3 0.12. The trouble is that I don't know how to return self from the __enter__ function. I don't have this issue for implementing iterators that are their own iterators.
I can work around this by not using the context protocol and simply using methods inside the pymethods block.
Code that I'm trying to make work: https://github.com/jothan/cordoba/blob/cf8c6deb809d73948c8c47677c6b92b799588131/src/pymod.rs#L200
Iterator that can return self: https://github.com/jothan/cordoba/blob/cf8c6deb809d73948c8c47677c6b92b799588131/src/pymod.rs#L118
Thanks, yes this is sadly a flaw with the #[pyproto] design at the moment which I've been aware of for a while but not found the right moment to fix. Perhaps this is now a good time. I've opened #1206 and will try to take a spin at this soon.
For now, I'm happy to write a temporary solution (i.e. allow PyRefMut) for this.
@davidhewitt What do you think?
I think what I have in mind is non-breaking and not _too hard_ so I can do over the weekend and we can potentially even release in a 0.12.2.
Most helpful comment
I think what I have in mind is non-breaking and not _too hard_ so I can do over the weekend and we can potentially even release in a 0.12.2.