1use crate::{stub_type::ModuleRef, PyStubType, TypeInfo};
25use std::any::TypeId;
26
27#[derive(Debug, Clone, Copy, PartialEq)]
29pub enum IgnoreTarget {
30 All,
32 Specified(&'static [&'static str]),
34}
35
36#[derive(Debug, Clone, PartialEq)]
38pub struct DeprecatedInfo {
39 pub since: Option<&'static str>,
40 pub note: Option<&'static str>,
41}
42
43pub fn compare_op_type_input() -> TypeInfo {
46 <isize as PyStubType>::type_input()
47}
48
49pub fn no_return_type_output() -> TypeInfo {
50 TypeInfo::none()
51}
52
53#[derive(Debug, Clone, Copy, PartialEq, Eq)]
55pub enum ParameterKind {
56 PositionalOnly,
58 PositionalOrKeyword,
60 KeywordOnly,
62 VarPositional,
64 VarKeyword,
66}
67
68#[derive(Debug, Clone)]
70pub enum ParameterDefault {
71 None,
73 Expr {
75 value: fn() -> String,
77 source_module: Option<fn() -> Option<ModuleRef>>,
79 },
80}
81
82impl PartialEq for ParameterDefault {
83 #[inline]
84 fn eq(&self, other: &Self) -> bool {
85 match (self, other) {
86 (Self::Expr { value: l, .. }, Self::Expr { value: r, .. }) => {
87 let l_val = l();
88 let r_val = r();
89 l_val.eq(&r_val)
90 }
91 (Self::None, Self::None) => true,
92 _ => false,
93 }
94 }
95}
96
97#[derive(Debug)]
102pub struct ParameterInfo {
103 pub name: &'static str,
105 pub kind: ParameterKind,
107 pub type_info: fn() -> TypeInfo,
109 pub default: ParameterDefault,
111}
112
113#[derive(Debug, Clone, Copy, PartialEq)]
115pub enum MethodType {
116 Instance,
117 Static,
118 Class,
119 New,
120}
121
122#[derive(Debug)]
124pub struct MethodInfo {
125 pub name: &'static str,
126 pub parameters: &'static [ParameterInfo],
127 pub r#return: fn() -> TypeInfo,
128 pub doc: &'static str,
129 pub r#type: MethodType,
130 pub is_async: bool,
131 pub deprecated: Option<DeprecatedInfo>,
132 pub type_ignored: Option<IgnoreTarget>,
133 pub is_overload: bool,
135}
136
137#[derive(Debug)]
139pub struct MemberInfo {
140 pub name: &'static str,
141 pub r#type: fn() -> TypeInfo,
142 pub doc: &'static str,
143 pub default: Option<fn() -> String>,
144 pub deprecated: Option<DeprecatedInfo>,
145}
146
147#[derive(Debug)]
149pub struct PyMethodsInfo {
150 pub struct_id: fn() -> TypeId,
152 pub attrs: &'static [MemberInfo],
154 pub getters: &'static [MemberInfo],
156 pub setters: &'static [MemberInfo],
158 pub methods: &'static [MethodInfo],
160 pub file: &'static str,
162 pub line: u32,
163 pub column: u32,
164}
165
166inventory::collect!(PyMethodsInfo);
167
168#[derive(Debug)]
170pub struct PyClassInfo {
171 pub struct_id: fn() -> TypeId,
173 pub pyclass_name: &'static str,
175 pub module: Option<&'static str>,
177 pub doc: &'static str,
179 pub getters: &'static [MemberInfo],
181 pub setters: &'static [MemberInfo],
183 pub bases: &'static [fn() -> TypeInfo],
185 pub has_eq: bool,
187 pub has_ord: bool,
189 pub has_hash: bool,
191 pub has_str: bool,
193 pub subclass: bool,
195}
196
197inventory::collect!(PyClassInfo);
198
199#[derive(Debug, Clone, Copy, PartialEq)]
200pub enum VariantForm {
201 Unit,
202 Tuple,
203 Struct,
204}
205
206#[derive(Debug)]
208pub struct VariantInfo {
209 pub pyclass_name: &'static str,
210 pub module: Option<&'static str>,
211 pub doc: &'static str,
212 pub fields: &'static [MemberInfo],
213 pub form: &'static VariantForm,
214 pub constr_args: &'static [ParameterInfo],
215}
216
217#[derive(Debug)]
219pub struct PyComplexEnumInfo {
220 pub enum_id: fn() -> TypeId,
222 pub pyclass_name: &'static str,
224 pub module: Option<&'static str>,
226 pub doc: &'static str,
228 pub variants: &'static [VariantInfo],
230}
231
232inventory::collect!(PyComplexEnumInfo);
233
234#[derive(Debug)]
236pub struct PyEnumInfo {
237 pub enum_id: fn() -> TypeId,
239 pub pyclass_name: &'static str,
241 pub module: Option<&'static str>,
243 pub doc: &'static str,
245 pub variants: &'static [(&'static str, &'static str)],
247}
248
249inventory::collect!(PyEnumInfo);
250
251#[derive(Debug)]
253pub struct PyFunctionInfo {
254 pub name: &'static str,
255 pub parameters: &'static [ParameterInfo],
256 pub r#return: fn() -> TypeInfo,
257 pub doc: &'static str,
258 pub module: Option<&'static str>,
259 pub is_async: bool,
260 pub deprecated: Option<DeprecatedInfo>,
261 pub type_ignored: Option<IgnoreTarget>,
262 pub is_overload: bool,
264 pub file: &'static str,
266 pub line: u32,
267 pub column: u32,
268 pub index: usize,
270}
271
272inventory::collect!(PyFunctionInfo);
273
274#[derive(Debug)]
275pub struct PyVariableInfo {
276 pub name: &'static str,
277 pub module: &'static str,
278 pub r#type: fn() -> TypeInfo,
279 pub default: Option<fn() -> String>,
280}
281
282inventory::collect!(PyVariableInfo);
283
284#[derive(Debug)]
285pub struct TypeAliasInfo {
286 pub name: &'static str,
287 pub module: &'static str,
288 pub r#type: fn() -> TypeInfo,
289 pub doc: &'static str,
290}
291
292inventory::collect!(TypeAliasInfo);
293
294#[derive(Debug)]
295pub struct ModuleDocInfo {
296 pub module: &'static str,
297 pub doc: fn() -> String,
298}
299
300inventory::collect!(ModuleDocInfo);
301
302#[derive(Debug)]
304pub struct ReexportModuleMembers {
305 pub target_module: &'static str,
306 pub source_module: &'static str,
307 pub items: Option<&'static [&'static str]>,
308}
309
310inventory::collect!(ReexportModuleMembers);
311
312#[derive(Debug)]
314pub struct ExportVerbatim {
315 pub target_module: &'static str,
316 pub name: &'static str,
317}
318
319inventory::collect!(ExportVerbatim);
320
321#[derive(Debug)]
323pub struct ExcludeFromAll {
324 pub target_module: &'static str,
325 pub name: &'static str,
326}
327
328inventory::collect!(ExcludeFromAll);