pyo3_stub_gen/
type_info.rs1use crate::{PyStubType, TypeInfo};
25use std::any::TypeId;
26
27#[derive(Debug, Clone, PartialEq)]
29pub struct DeprecatedInfo {
30 pub since: Option<&'static str>,
31 pub note: Option<&'static str>,
32}
33
34pub fn compare_op_type_input() -> TypeInfo {
37 <isize as PyStubType>::type_input()
38}
39
40pub fn no_return_type_output() -> TypeInfo {
41 TypeInfo::none()
42}
43
44#[derive(Debug)]
46pub struct ArgInfo {
47 pub name: &'static str,
48 pub r#type: fn() -> TypeInfo,
49 pub signature: Option<SignatureArg>,
50}
51#[derive(Debug, Clone)]
52pub enum SignatureArg {
53 Ident,
54 Assign {
55 default: &'static std::sync::LazyLock<String>,
56 },
57 Star,
58 Args,
59 Keywords,
60}
61
62impl PartialEq for SignatureArg {
63 #[inline]
64 fn eq(&self, other: &Self) -> bool {
65 match (self, other) {
66 (Self::Assign { default: l_default }, Self::Assign { default: r_default }) => {
67 let l_default: &String = l_default;
68 let r_default: &String = r_default;
69 l_default.eq(r_default)
70 }
71 _ => core::mem::discriminant(self) == core::mem::discriminant(other),
72 }
73 }
74}
75
76#[derive(Debug, Clone, Copy, PartialEq)]
78pub enum MethodType {
79 Instance,
80 Static,
81 Class,
82 New,
83}
84
85#[derive(Debug)]
87pub struct MethodInfo {
88 pub name: &'static str,
89 pub args: &'static [ArgInfo],
90 pub r#return: fn() -> TypeInfo,
91 pub doc: &'static str,
92 pub r#type: MethodType,
93 pub is_async: bool,
94 pub deprecated: Option<DeprecatedInfo>,
95}
96
97#[derive(Debug)]
99pub struct MemberInfo {
100 pub name: &'static str,
101 pub r#type: fn() -> TypeInfo,
102 pub doc: &'static str,
103 pub default: Option<&'static std::sync::LazyLock<String>>,
104}
105
106#[derive(Debug)]
108pub struct PyMethodsInfo {
109 pub struct_id: fn() -> TypeId,
111 pub attrs: &'static [MemberInfo],
113 pub getters: &'static [MemberInfo],
115 pub setters: &'static [MemberInfo],
117 pub methods: &'static [MethodInfo],
119}
120
121inventory::collect!(PyMethodsInfo);
122
123#[derive(Debug)]
125pub struct PyClassInfo {
126 pub struct_id: fn() -> TypeId,
128 pub pyclass_name: &'static str,
130 pub module: Option<&'static str>,
132 pub doc: &'static str,
134 pub getters: &'static [MemberInfo],
136 pub setters: &'static [MemberInfo],
138 pub bases: &'static [fn() -> TypeInfo],
140}
141
142inventory::collect!(PyClassInfo);
143
144#[derive(Debug, Clone, Copy, PartialEq)]
145pub enum VariantForm {
146 Unit,
147 Tuple,
148 Struct,
149}
150
151#[derive(Debug)]
153pub struct VariantInfo {
154 pub pyclass_name: &'static str,
155 pub module: Option<&'static str>,
156 pub doc: &'static str,
157 pub fields: &'static [MemberInfo],
158 pub form: &'static VariantForm,
159 pub constr_args: &'static [ArgInfo],
160}
161
162#[derive(Debug)]
164pub struct PyComplexEnumInfo {
165 pub enum_id: fn() -> TypeId,
167 pub pyclass_name: &'static str,
169 pub module: Option<&'static str>,
171 pub doc: &'static str,
173 pub variants: &'static [VariantInfo],
175}
176
177inventory::collect!(PyComplexEnumInfo);
178
179#[derive(Debug)]
181pub struct PyEnumInfo {
182 pub enum_id: fn() -> TypeId,
184 pub pyclass_name: &'static str,
186 pub module: Option<&'static str>,
188 pub doc: &'static str,
190 pub variants: &'static [(&'static str, &'static str)],
192}
193
194inventory::collect!(PyEnumInfo);
195
196#[derive(Debug)]
198pub struct PyFunctionInfo {
199 pub name: &'static str,
200 pub args: &'static [ArgInfo],
201 pub r#return: fn() -> TypeInfo,
202 pub doc: &'static str,
203 pub module: Option<&'static str>,
204 pub is_async: bool,
205 pub deprecated: Option<DeprecatedInfo>,
206}
207
208inventory::collect!(PyFunctionInfo);
209
210#[derive(Debug)]
211pub struct PyErrorInfo {
212 pub name: &'static str,
213 pub module: &'static str,
214 pub base: fn() -> &'static str,
215}
216
217inventory::collect!(PyErrorInfo);
218
219#[derive(Debug)]
220pub struct PyVariableInfo {
221 pub name: &'static str,
222 pub module: &'static str,
223 pub r#type: fn() -> TypeInfo,
224}
225
226inventory::collect!(PyVariableInfo);