@@ -18,23 +18,66 @@ impl Boundness {
18
18
}
19
19
}
20
20
21
+ /// Indicates whether a symbol is re-exported using the [import conventions].
22
+ ///
23
+ /// [import conventions]: https://typing.readthedocs.io/en/latest/spec/distributing.html#import-conventions
21
24
#[ derive( Debug , Clone , Copy , PartialEq , Eq ) ]
22
25
pub ( crate ) enum ReExport {
23
- Implicit ,
24
- Explicit ,
25
- None ,
26
+ /// Symbol is either defined by an import statement and is re-exported, or it could be defined
27
+ /// by any other statement or expression.
28
+ ///
29
+ /// For example, in the following code:
30
+ /// ```py
31
+ /// import foo as foo
32
+ /// from foo import Bar as Bar
33
+ ///
34
+ /// baz = 1
35
+ /// ```
36
+ ///
37
+ /// All the symbols (`foo`, `Bar`, and `baz`) are re-exported.
38
+ Yes ,
39
+
40
+ /// Symbol is defined by an import statement and is not re-exported.
41
+ ///
42
+ /// For example, in the following code:
43
+ /// ```py
44
+ /// import foo
45
+ /// from foo import Bar
46
+ /// ```
47
+ ///
48
+ /// Both `foo` (module) and `Bar` are not re-exported.
49
+ No ,
50
+
51
+ /// Symbol is maybe re-exported.
52
+ ///
53
+ /// For example, in the following code:
54
+ /// ```py
55
+ /// if flag:
56
+ /// import foo
57
+ /// else:
58
+ /// import foo as foo
59
+ /// ```
60
+ ///
61
+ /// The `foo` symbol is maybe re-exported, depending on the value of `flag`.
62
+ ///
63
+ /// Or, in the following code:
64
+ /// ```py
65
+ /// import foo
66
+ ///
67
+ /// if flag:
68
+ /// foo: int = 1
69
+ /// ```
70
+ ///
71
+ /// The `foo` symbol is maybe re-exported if the truthiness of `flag` is ambiguous.
72
+ Maybe ,
26
73
}
27
74
28
75
impl ReExport {
29
- pub ( crate ) const fn is_implicit ( self ) -> bool {
30
- matches ! ( self , ReExport :: Implicit )
31
- }
32
-
33
76
pub ( crate ) fn or ( self , other : ReExport ) -> ReExport {
34
77
match ( self , other) {
35
- ( ReExport :: Implicit , _ ) | ( _ , ReExport :: Implicit ) => ReExport :: Implicit ,
36
- ( ReExport :: Explicit , ReExport :: Explicit ) => ReExport :: Explicit ,
37
- ( non_none , ReExport :: None ) | ( ReExport :: None , non_none ) => non_none ,
78
+ ( ReExport :: Yes , ReExport :: Yes ) => ReExport :: Yes ,
79
+ ( ReExport :: No , ReExport :: No ) => ReExport :: No ,
80
+ _ => ReExport :: Maybe ,
38
81
}
39
82
}
40
83
}
@@ -139,53 +182,53 @@ mod tests {
139
182
) ;
140
183
assert_eq ! (
141
184
Symbol :: Unbound
142
- . or_fall_back_to( & db, & Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound ) ) ,
143
- Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound )
185
+ . or_fall_back_to( & db, & Symbol :: Type ( ty1, ReExport :: Yes , PossiblyUnbound ) ) ,
186
+ Symbol :: Type ( ty1, ReExport :: Yes , PossiblyUnbound )
144
187
) ;
145
188
assert_eq ! (
146
- Symbol :: Unbound . or_fall_back_to( & db, & Symbol :: Type ( ty1, ReExport :: None , Bound ) ) ,
147
- Symbol :: Type ( ty1, ReExport :: None , Bound )
189
+ Symbol :: Unbound . or_fall_back_to( & db, & Symbol :: Type ( ty1, ReExport :: Yes , Bound ) ) ,
190
+ Symbol :: Type ( ty1, ReExport :: Yes , Bound )
148
191
) ;
149
192
150
193
// Start from a possibly unbound symbol
151
194
assert_eq ! (
152
- Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound )
195
+ Symbol :: Type ( ty1, ReExport :: Yes , PossiblyUnbound )
153
196
. or_fall_back_to( & db, & Symbol :: Unbound ) ,
154
- Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound )
197
+ Symbol :: Type ( ty1, ReExport :: Yes , PossiblyUnbound )
155
198
) ;
156
199
assert_eq ! (
157
- Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound )
158
- . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: None , PossiblyUnbound ) ) ,
200
+ Symbol :: Type ( ty1, ReExport :: Yes , PossiblyUnbound )
201
+ . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: Yes , PossiblyUnbound ) ) ,
159
202
Symbol :: Type (
160
203
UnionType :: from_elements( & db, [ ty2, ty1] ) ,
161
- ReExport :: None ,
204
+ ReExport :: Yes ,
162
205
PossiblyUnbound
163
206
)
164
207
) ;
165
208
assert_eq ! (
166
- Symbol :: Type ( ty1, ReExport :: None , PossiblyUnbound )
167
- . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: None , Bound ) ) ,
209
+ Symbol :: Type ( ty1, ReExport :: Yes , PossiblyUnbound )
210
+ . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: Yes , Bound ) ) ,
168
211
Symbol :: Type (
169
212
UnionType :: from_elements( & db, [ ty2, ty1] ) ,
170
- ReExport :: None ,
213
+ ReExport :: Yes ,
171
214
Bound
172
215
)
173
216
) ;
174
217
175
218
// Start from a definitely bound symbol
176
219
assert_eq ! (
177
- Symbol :: Type ( ty1, ReExport :: None , Bound ) . or_fall_back_to( & db, & Symbol :: Unbound ) ,
178
- Symbol :: Type ( ty1, ReExport :: None , Bound )
220
+ Symbol :: Type ( ty1, ReExport :: Yes , Bound ) . or_fall_back_to( & db, & Symbol :: Unbound ) ,
221
+ Symbol :: Type ( ty1, ReExport :: Yes , Bound )
179
222
) ;
180
223
assert_eq ! (
181
- Symbol :: Type ( ty1, ReExport :: None , Bound )
182
- . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: None , PossiblyUnbound ) ) ,
183
- Symbol :: Type ( ty1, ReExport :: None , Bound )
224
+ Symbol :: Type ( ty1, ReExport :: Yes , Bound )
225
+ . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: Yes , PossiblyUnbound ) ) ,
226
+ Symbol :: Type ( ty1, ReExport :: Yes , Bound )
184
227
) ;
185
228
assert_eq ! (
186
- Symbol :: Type ( ty1, ReExport :: None , Bound )
187
- . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: None , Bound ) ) ,
188
- Symbol :: Type ( ty1, ReExport :: None , Bound )
229
+ Symbol :: Type ( ty1, ReExport :: Yes , Bound )
230
+ . or_fall_back_to( & db, & Symbol :: Type ( ty2, ReExport :: Yes , Bound ) ) ,
231
+ Symbol :: Type ( ty1, ReExport :: Yes , Bound )
189
232
) ;
190
233
}
191
234
}
0 commit comments