@@ -7,13 +7,17 @@ mod numpy;
7
7
8
8
use maplit:: hashset;
9
9
use std:: { collections:: HashSet , fmt, ops} ;
10
-
11
- #[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Default , Hash ) ]
10
+ /**
11
+ * Indicates the dependent module or type;
12
+ * dependent module('import module', eg builtins): name="" , module = module name;
13
+ * dependent type(eg class enum)('from module import type'): name=type name , module = module name(which type defined).
14
+ */
15
+ #[ derive( Debug , Clone , PartialEq , Eq , PartialOrd , Ord , Default , Hash ) ]
12
16
pub struct ModuleRef {
13
17
pub name : String ,
14
18
pub module : String ,
15
19
}
16
-
20
+ /// From the dependent module
17
21
impl From < & str > for ModuleRef {
18
22
fn from ( m : & str ) -> Self {
19
23
Self { name : "" . to_string ( ) , module : m. to_string ( ) }
@@ -124,23 +128,32 @@ impl TypeInfo {
124
128
/// ```
125
129
/// pyo3_stub_gen::TypeInfo::with_module("pathlib.Path", "pathlib".into());
126
130
/// ```
127
- pub fn with_module_fix ( name : & str , module : ModuleRef , rust_flag : bool ) -> Self {
131
+ pub fn with_module ( name : & str , module : ModuleRef ) -> Self
132
+ {
128
133
let mut import = HashSet :: new ( ) ;
129
- //println!("{}", format!("name: {}, module: {}", name.to_string(), module));
130
- let mut module_fix = module. clone ( ) ;
131
- if rust_flag {
132
- module_fix. name = name. to_string ( ) ;
133
- }
134
- import. insert ( module_fix) ;
134
+ import. insert ( module) ;
135
135
Self {
136
136
name : name. to_string ( ) ,
137
137
import,
138
138
}
139
139
}
140
140
141
- pub fn with_module ( name : & str , module : ModuleRef ) -> Self
142
- {
143
- TypeInfo :: with_module_fix ( name, module, false )
141
+ /// A type annotation of a type that must be imported.
142
+ ///
143
+ /// ```
144
+ /// ClassA defined in ModuleA
145
+ /// pyo3_stub_gen::TypeInfo::with_type("ClassA", "ModuleA");
146
+ /// ```
147
+ pub fn with_type ( type_name : & str , module : ModuleRef ) -> Self {
148
+ let mut import = HashSet :: new ( ) ;
149
+ let mut type_ref: ModuleRef = module. clone ( ) ;
150
+ type_ref. name = type_name. to_string ( ) ;
151
+ import. insert ( type_ref) ;
152
+
153
+ Self {
154
+ name : type_name. to_string ( ) ,
155
+ import,
156
+ }
144
157
}
145
158
}
146
159
0 commit comments