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)]
55pub struct ArgInfo {
56 pub name: &'static str,
57 pub r#type: fn() -> TypeInfo,
58 pub signature: Option<SignatureArg>,
59}
60#[derive(Debug, Clone)]
61pub enum SignatureArg {
62 Ident,
63 Assign { default: fn() -> String },
64 Star,
65 Args,
66 Keywords,
67}
68
69impl PartialEq for SignatureArg {
70 #[inline]
71 fn eq(&self, other: &Self) -> bool {
72 match (self, other) {
73 (Self::Assign { default: l_default }, Self::Assign { default: r_default }) => {
74 let l_default = l_default();
75 let r_default = r_default();
76 l_default.eq(&r_default)
77 }
78 _ => core::mem::discriminant(self) == core::mem::discriminant(other),
79 }
80 }
81}
82
83#[derive(Debug, Clone, Copy, PartialEq)]
85pub enum MethodType {
86 Instance,
87 Static,
88 Class,
89 New,
90}
91
92#[derive(Debug)]
94pub struct MethodInfo {
95 pub name: &'static str,
96 pub args: &'static [ArgInfo],
97 pub r#return: fn() -> TypeInfo,
98 pub doc: &'static str,
99 pub r#type: MethodType,
100 pub is_async: bool,
101 pub deprecated: Option<DeprecatedInfo>,
102 pub type_ignored: Option<IgnoreTarget>,
103}
104
105#[derive(Debug)]
107pub struct MemberInfo {
108 pub name: &'static str,
109 pub r#type: fn() -> TypeInfo,
110 pub doc: &'static str,
111 pub default: Option<fn() -> String>,
112 pub deprecated: Option<DeprecatedInfo>,
113}
114
115#[derive(Debug)]
117pub struct PyMethodsInfo {
118 pub struct_id: fn() -> TypeId,
120 pub attrs: &'static [MemberInfo],
122 pub getters: &'static [MemberInfo],
124 pub setters: &'static [MemberInfo],
126 pub methods: &'static [MethodInfo],
128}
129
130inventory::collect!(PyMethodsInfo);
131
132#[derive(Debug)]
134pub struct PyClassInfo {
135 pub struct_id: fn() -> TypeId,
137 pub pyclass_name: &'static str,
139 pub module: Option<&'static str>,
141 pub doc: &'static str,
143 pub getters: &'static [MemberInfo],
145 pub setters: &'static [MemberInfo],
147 pub bases: &'static [fn() -> TypeInfo],
149 pub has_eq: bool,
151 pub has_ord: bool,
153 pub has_hash: bool,
155 pub has_str: bool,
157}
158
159inventory::collect!(PyClassInfo);
160
161#[derive(Debug, Clone, Copy, PartialEq)]
162pub enum VariantForm {
163 Unit,
164 Tuple,
165 Struct,
166}
167
168#[derive(Debug)]
170pub struct VariantInfo {
171 pub pyclass_name: &'static str,
172 pub module: Option<&'static str>,
173 pub doc: &'static str,
174 pub fields: &'static [MemberInfo],
175 pub form: &'static VariantForm,
176 pub constr_args: &'static [ArgInfo],
177}
178
179#[derive(Debug)]
181pub struct PyComplexEnumInfo {
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 [VariantInfo],
192}
193
194inventory::collect!(PyComplexEnumInfo);
195
196#[derive(Debug)]
198pub struct PyEnumInfo {
199 pub enum_id: fn() -> TypeId,
201 pub pyclass_name: &'static str,
203 pub module: Option<&'static str>,
205 pub doc: &'static str,
207 pub variants: &'static [(&'static str, &'static str)],
209}
210
211inventory::collect!(PyEnumInfo);
212
213#[derive(Debug)]
215pub struct PyFunctionInfo {
216 pub name: &'static str,
217 pub args: &'static [ArgInfo],
218 pub r#return: fn() -> TypeInfo,
219 pub doc: &'static str,
220 pub module: Option<&'static str>,
221 pub is_async: bool,
222 pub deprecated: Option<DeprecatedInfo>,
223 pub type_ignored: Option<IgnoreTarget>,
224}
225
226inventory::collect!(PyFunctionInfo);
227
228#[derive(Debug)]
229pub struct PyVariableInfo {
230 pub name: &'static str,
231 pub module: &'static str,
232 pub r#type: fn() -> TypeInfo,
233 pub default: Option<fn() -> String>,
234}
235
236inventory::collect!(PyVariableInfo);
237
238#[derive(Debug)]
239pub struct ModuleDocInfo {
240 pub module: &'static str,
241 pub doc: fn() -> String,
242}
243
244inventory::collect!(ModuleDocInfo);