pyo3_stub_gen/generate/
error.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
use crate::type_info::*;
use std::fmt;

/// Definition of a Python execption.
#[derive(Debug, Clone, PartialEq)]
pub struct ErrorDef {
    pub name: &'static str,
    pub base: &'static str,
}

impl From<&PyErrorInfo> for ErrorDef {
    fn from(info: &PyErrorInfo) -> Self {
        Self {
            name: info.name,
            base: (info.base)(),
        }
    }
}

impl fmt::Display for ErrorDef {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        writeln!(f, "class {}({}): ...", self.name, self.base)
    }
}