Skip to content

PyErr does not implement std::error::Error #682

Closed
@nagisa

Description

@nagisa

PyErr is a very odd structure. It pretends to emulate the 3-tuple returned by PyErr_Fetch, but then its pvalue is a 3-variant that also allows lazy construction of exception objects.

As thus it fails to implement a couple of traits typically expected of the error type (std::error::Error, std::fmt::Display, Sync and Send) and does not integrate very well with the error handling story in Python.

There are a couple of ways to go forward here, but one of the simpler things that could be done I think is:

  1. Add a method along the lines of fn(Python, PyErr) -> Py<BaseException>;
    • I don’t believe this can be done easily right now without unsafe code.
  2. Implement the typical error traits for Py<ExceptionT> types.
    • Specifically for Display and friends I think it is fine to just do a Python::acquire_gil() inside if that is necessary to format the data.

Willing to contribute the necessary code to implement this. Please let me know what you think about this. Perhaps other approaches seem better?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions