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 pub subclass: bool,
159}
160
161inventory::collect!(PyClassInfo);
162
163#[derive(Debug, Clone, Copy, PartialEq)]
164pub enum VariantForm {
165 Unit,
166 Tuple,
167 Struct,
168}
169
170#[derive(Debug)]
172pub struct VariantInfo {
173 pub pyclass_name: &'static str,
174 pub module: Option<&'static str>,
175 pub doc: &'static str,
176 pub fields: &'static [MemberInfo],
177 pub form: &'static VariantForm,
178 pub constr_args: &'static [ArgInfo],
179}
180
181#[derive(Debug)]
183pub struct PyComplexEnumInfo {
184 pub enum_id: fn() -> TypeId,
186 pub pyclass_name: &'static str,
188 pub module: Option<&'static str>,
190 pub doc: &'static str,
192 pub variants: &'static [VariantInfo],
194}
195
196inventory::collect!(PyComplexEnumInfo);
197
198#[derive(Debug)]
200pub struct PyEnumInfo {
201 pub enum_id: fn() -> TypeId,
203 pub pyclass_name: &'static str,
205 pub module: Option<&'static str>,
207 pub doc: &'static str,
209 pub variants: &'static [(&'static str, &'static str)],
211}
212
213inventory::collect!(PyEnumInfo);
214
215#[derive(Debug)]
217pub struct PyFunctionInfo {
218 pub name: &'static str,
219 pub args: &'static [ArgInfo],
220 pub r#return: fn() -> TypeInfo,
221 pub doc: &'static str,
222 pub module: Option<&'static str>,
223 pub is_async: bool,
224 pub deprecated: Option<DeprecatedInfo>,
225 pub type_ignored: Option<IgnoreTarget>,
226}
227
228inventory::collect!(PyFunctionInfo);
229
230#[derive(Debug)]
231pub struct PyVariableInfo {
232 pub name: &'static str,
233 pub module: &'static str,
234 pub r#type: fn() -> TypeInfo,
235 pub default: Option<fn() -> String>,
236}
237
238inventory::collect!(PyVariableInfo);
239
240#[derive(Debug)]
241pub struct ModuleDocInfo {
242 pub module: &'static str,
243 pub doc: fn() -> String,
244}
245
246inventory::collect!(ModuleDocInfo);