Skip to content

Conversation

@tpoliaw
Copy link
Contributor

@tpoliaw tpoliaw commented Nov 4, 2025

Path::into_pyobject now returns a pathlib.Path object which doesn't work
as expected when added to sys.path so revert to string (see #4925).

impl FromPyObject for PyRefMut now returns a custom error type (that
doesn't impl std::error::Error) so map the error back to PyErr to
return it (see #5413).

@tpoliaw
Copy link
Contributor Author

tpoliaw commented Nov 4, 2025

Should fix #5570

For the errors, I initially tried adding impl Error for the new errors but the lifetimes didn't allow them to be returned from Python::attach. Is it worth adding them anyway?

Path::into_pyobject now returns a pathlib.Path object which doesn't work
as expected when added to sys.path so revert to string (see PyO3#4925).

`impl FromPyObject for PyRefMut` now returns a custom error type (that
doesn't impl `std::error::Error`) so map the error back the PyErr to
return it (see PyO3#5413).
@tpoliaw tpoliaw force-pushed the fix-plugin-example branch from 740267f to b0c5ba2 Compare November 4, 2025 23:02
@danferns
Copy link

danferns commented Nov 6, 2025

Thank you for updating the example, I just tried running it and it works without any issues! 😄

@danferns
Copy link

danferns commented Nov 6, 2025

For the errors, I initially tried adding impl Error for the new errors but the lifetimes didn't allow them to be returned from Python::attach. Is it worth adding them anyway?

I had found that the cargo errors go away if the return type for main is set to PyResult<()> (without changing anything else).

fn main() -> PyResult<()> {
/// ...

@tpoliaw
Copy link
Contributor Author

tpoliaw commented Nov 6, 2025

I think that makes sense because it'll do the conversion to PyErr (that I've done manually here) automatically whereas it can't auto convert to Box<...>. I'll leave it up to @davidhewitt whether it's preferred to change the main return type or explicitly convert the errors. Or I suppose adding a type hint to attach could work as well?

@tpoliaw tpoliaw force-pushed the fix-plugin-example branch from c725183 to b0c5ba2 Compare November 7, 2025 10:42
Copy link
Member

@davidhewitt davidhewitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this! I think mapping the errors is fine for now 👍

@davidhewitt davidhewitt added this pull request to the merge queue Nov 8, 2025
Merged via the queue into PyO3:main with commit d2d36b4 Nov 8, 2025
84 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants