1use crate::{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(fn() -> String),
75}
76
77impl PartialEq for ParameterDefault {
78 #[inline]
79 fn eq(&self, other: &Self) -> bool {
80 match (self, other) {
81 (Self::Expr(l), Self::Expr(r)) => {
82 let l_val = l();
83 let r_val = r();
84 l_val.eq(&r_val)
85 }
86 (Self::None, Self::None) => true,
87 _ => false,
88 }
89 }
90}
91
92#[derive(Debug)]
97pub struct ParameterInfo {
98 pub name: &'static str,
100 pub kind: ParameterKind,
102 pub type_info: fn() -> TypeInfo,
104 pub default: ParameterDefault,
106}
107
108#[derive(Debug, Clone, Copy, PartialEq)]
110pub enum MethodType {
111 Instance,
112 Static,
113 Class,
114 New,
115}
116
117#[derive(Debug)]
119pub struct MethodInfo {
120 pub name: &'static str,
121 pub parameters: &'static [ParameterInfo],
122 pub r#return: fn() -> TypeInfo,
123 pub doc: &'static str,
124 pub r#type: MethodType,
125 pub is_async: bool,
126 pub deprecated: Option<DeprecatedInfo>,
127 pub type_ignored: Option<IgnoreTarget>,
128 pub is_overload: bool,
130}
131
132#[derive(Debug)]
134pub struct MemberInfo {
135 pub name: &'static str,
136 pub r#type: fn() -> TypeInfo,
137 pub doc: &'static str,
138 pub default: Option<fn() -> String>,
139 pub deprecated: Option<DeprecatedInfo>,
140}
141
142#[derive(Debug)]
144pub struct PyMethodsInfo {
145 pub struct_id: fn() -> TypeId,
147 pub attrs: &'static [MemberInfo],
149 pub getters: &'static [MemberInfo],
151 pub setters: &'static [MemberInfo],
153 pub methods: &'static [MethodInfo],
155 pub file: &'static str,
157 pub line: u32,
158 pub column: u32,
159}
160
161inventory::collect!(PyMethodsInfo);
162
163#[derive(Debug)]
165pub struct PyClassInfo {
166 pub struct_id: fn() -> TypeId,
168 pub pyclass_name: &'static str,
170 pub module: Option<&'static str>,
172 pub doc: &'static str,
174 pub getters: &'static [MemberInfo],
176 pub setters: &'static [MemberInfo],
178 pub bases: &'static [fn() -> TypeInfo],
180 pub has_eq: bool,
182 pub has_ord: bool,
184 pub has_hash: bool,
186 pub has_str: bool,
188 pub subclass: bool,
190}
191
192inventory::collect!(PyClassInfo);
193
194#[derive(Debug, Clone, Copy, PartialEq)]
195pub enum VariantForm {
196 Unit,
197 Tuple,
198 Struct,
199}
200
201#[derive(Debug)]
203pub struct VariantInfo {
204 pub pyclass_name: &'static str,
205 pub module: Option<&'static str>,
206 pub doc: &'static str,
207 pub fields: &'static [MemberInfo],
208 pub form: &'static VariantForm,
209 pub constr_args: &'static [ParameterInfo],
210}
211
212#[derive(Debug)]
214pub struct PyComplexEnumInfo {
215 pub enum_id: fn() -> TypeId,
217 pub pyclass_name: &'static str,
219 pub module: Option<&'static str>,
221 pub doc: &'static str,
223 pub variants: &'static [VariantInfo],
225}
226
227inventory::collect!(PyComplexEnumInfo);
228
229#[derive(Debug)]
231pub struct PyEnumInfo {
232 pub enum_id: fn() -> TypeId,
234 pub pyclass_name: &'static str,
236 pub module: Option<&'static str>,
238 pub doc: &'static str,
240 pub variants: &'static [(&'static str, &'static str)],
242}
243
244inventory::collect!(PyEnumInfo);
245
246#[derive(Debug)]
248pub struct PyFunctionInfo {
249 pub name: &'static str,
250 pub parameters: &'static [ParameterInfo],
251 pub r#return: fn() -> TypeInfo,
252 pub doc: &'static str,
253 pub module: Option<&'static str>,
254 pub is_async: bool,
255 pub deprecated: Option<DeprecatedInfo>,
256 pub type_ignored: Option<IgnoreTarget>,
257 pub is_overload: bool,
259 pub file: &'static str,
261 pub line: u32,
262 pub column: u32,
263 pub index: usize,
265}
266
267inventory::collect!(PyFunctionInfo);
268
269#[derive(Debug)]
270pub struct PyVariableInfo {
271 pub name: &'static str,
272 pub module: &'static str,
273 pub r#type: fn() -> TypeInfo,
274 pub default: Option<fn() -> String>,
275}
276
277inventory::collect!(PyVariableInfo);
278
279#[derive(Debug)]
280pub struct TypeAliasInfo {
281 pub name: &'static str,
282 pub module: &'static str,
283 pub r#type: fn() -> TypeInfo,
284 pub doc: &'static str,
285}
286
287inventory::collect!(TypeAliasInfo);
288
289#[derive(Debug)]
290pub struct ModuleDocInfo {
291 pub module: &'static str,
292 pub doc: fn() -> String,
293}
294
295inventory::collect!(ModuleDocInfo);
296
297#[derive(Debug)]
299pub struct ReexportModuleMembers {
300 pub target_module: &'static str,
301 pub source_module: &'static str,
302 pub items: Option<&'static [&'static str]>,
303}
304
305inventory::collect!(ReexportModuleMembers);
306
307#[derive(Debug)]
309pub struct ExportVerbatim {
310 pub target_module: &'static str,
311 pub name: &'static str,
312}
313
314inventory::collect!(ExportVerbatim);
315
316#[derive(Debug)]
318pub struct ExcludeFromAll {
319 pub target_module: &'static str,
320 pub name: &'static str,
321}
322
323inventory::collect!(ExcludeFromAll);