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 {
64 default: &'static std::sync::LazyLock<String>,
65 },
66 Star,
67 Args,
68 Keywords,
69}
70
71impl PartialEq for SignatureArg {
72 #[inline]
73 fn eq(&self, other: &Self) -> bool {
74 match (self, other) {
75 (Self::Assign { default: l_default }, Self::Assign { default: r_default }) => {
76 let l_default: &String = l_default;
77 let r_default: &String = r_default;
78 l_default.eq(r_default)
79 }
80 _ => core::mem::discriminant(self) == core::mem::discriminant(other),
81 }
82 }
83}
84
85#[derive(Debug, Clone, Copy, PartialEq)]
87pub enum MethodType {
88 Instance,
89 Static,
90 Class,
91 New,
92}
93
94#[derive(Debug)]
96pub struct MethodInfo {
97 pub name: &'static str,
98 pub args: &'static [ArgInfo],
99 pub r#return: fn() -> TypeInfo,
100 pub doc: &'static str,
101 pub r#type: MethodType,
102 pub is_async: bool,
103 pub deprecated: Option<DeprecatedInfo>,
104 pub type_ignored: Option<IgnoreTarget>,
105}
106
107#[derive(Debug)]
109pub struct MemberInfo {
110 pub name: &'static str,
111 pub r#type: fn() -> TypeInfo,
112 pub doc: &'static str,
113 pub default: Option<&'static std::sync::LazyLock<String>>,
114 pub deprecated: Option<DeprecatedInfo>,
115}
116
117#[derive(Debug)]
119pub struct PyMethodsInfo {
120 pub struct_id: fn() -> TypeId,
122 pub attrs: &'static [MemberInfo],
124 pub getters: &'static [MemberInfo],
126 pub setters: &'static [MemberInfo],
128 pub methods: &'static [MethodInfo],
130}
131
132inventory::collect!(PyMethodsInfo);
133
134#[derive(Debug)]
136pub struct PyClassInfo {
137 pub struct_id: fn() -> TypeId,
139 pub pyclass_name: &'static str,
141 pub module: Option<&'static str>,
143 pub doc: &'static str,
145 pub getters: &'static [MemberInfo],
147 pub setters: &'static [MemberInfo],
149 pub bases: &'static [fn() -> TypeInfo],
151 pub has_eq: bool,
153 pub has_ord: bool,
155 pub has_hash: bool,
157 pub has_str: 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}
236
237inventory::collect!(PyVariableInfo);