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}
129
130#[derive(Debug)]
132pub struct MemberInfo {
133 pub name: &'static str,
134 pub r#type: fn() -> TypeInfo,
135 pub doc: &'static str,
136 pub default: Option<fn() -> String>,
137 pub deprecated: Option<DeprecatedInfo>,
138}
139
140#[derive(Debug)]
142pub struct PyMethodsInfo {
143 pub struct_id: fn() -> TypeId,
145 pub attrs: &'static [MemberInfo],
147 pub getters: &'static [MemberInfo],
149 pub setters: &'static [MemberInfo],
151 pub methods: &'static [MethodInfo],
153}
154
155inventory::collect!(PyMethodsInfo);
156
157#[derive(Debug)]
159pub struct PyClassInfo {
160 pub struct_id: fn() -> TypeId,
162 pub pyclass_name: &'static str,
164 pub module: Option<&'static str>,
166 pub doc: &'static str,
168 pub getters: &'static [MemberInfo],
170 pub setters: &'static [MemberInfo],
172 pub bases: &'static [fn() -> TypeInfo],
174 pub has_eq: bool,
176 pub has_ord: bool,
178 pub has_hash: bool,
180 pub has_str: bool,
182 pub subclass: bool,
184}
185
186inventory::collect!(PyClassInfo);
187
188#[derive(Debug, Clone, Copy, PartialEq)]
189pub enum VariantForm {
190 Unit,
191 Tuple,
192 Struct,
193}
194
195#[derive(Debug)]
197pub struct VariantInfo {
198 pub pyclass_name: &'static str,
199 pub module: Option<&'static str>,
200 pub doc: &'static str,
201 pub fields: &'static [MemberInfo],
202 pub form: &'static VariantForm,
203 pub constr_args: &'static [ParameterInfo],
204}
205
206#[derive(Debug)]
208pub struct PyComplexEnumInfo {
209 pub enum_id: fn() -> TypeId,
211 pub pyclass_name: &'static str,
213 pub module: Option<&'static str>,
215 pub doc: &'static str,
217 pub variants: &'static [VariantInfo],
219}
220
221inventory::collect!(PyComplexEnumInfo);
222
223#[derive(Debug)]
225pub struct PyEnumInfo {
226 pub enum_id: fn() -> TypeId,
228 pub pyclass_name: &'static str,
230 pub module: Option<&'static str>,
232 pub doc: &'static str,
234 pub variants: &'static [(&'static str, &'static str)],
236}
237
238inventory::collect!(PyEnumInfo);
239
240#[derive(Debug)]
242pub struct PyFunctionInfo {
243 pub name: &'static str,
244 pub parameters: &'static [ParameterInfo],
245 pub r#return: fn() -> TypeInfo,
246 pub doc: &'static str,
247 pub module: Option<&'static str>,
248 pub is_async: bool,
249 pub deprecated: Option<DeprecatedInfo>,
250 pub type_ignored: Option<IgnoreTarget>,
251}
252
253inventory::collect!(PyFunctionInfo);
254
255#[derive(Debug)]
256pub struct PyVariableInfo {
257 pub name: &'static str,
258 pub module: &'static str,
259 pub r#type: fn() -> TypeInfo,
260 pub default: Option<fn() -> String>,
261}
262
263inventory::collect!(PyVariableInfo);
264
265#[derive(Debug)]
266pub struct ModuleDocInfo {
267 pub module: &'static str,
268 pub doc: fn() -> String,
269}
270
271inventory::collect!(ModuleDocInfo);