File tree 3 files changed +28
-0
lines changed
3 files changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -415,6 +415,15 @@ impl<'a> BindingsBuilder<'a> {
415
415
self . bind_narrow_ops ( & narrow_op, * range) ;
416
416
return ;
417
417
}
418
+ Expr :: Call ( ExprCall {
419
+ range : _,
420
+ func,
421
+ arguments : _,
422
+ } ) if self . as_special_export ( func) == Some ( SpecialExport :: Exit ) => {
423
+ // Control flow doesn't proceed after sys.exit()
424
+ self . scopes . current_mut ( ) . flow . no_next = true ;
425
+ false
426
+ }
418
427
Expr :: Name ( x) => {
419
428
let name = Ast :: expr_name_identifier ( x. clone ( ) ) ;
420
429
let binding = self . forward_lookup ( & name) ;
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ pub enum SpecialExport {
35
35
Optional ,
36
36
Cast ,
37
37
Super ,
38
+ Exit ,
38
39
}
39
40
40
41
#[ derive( Debug ) ]
@@ -70,6 +71,7 @@ impl SpecialExport {
70
71
"Optional" => Some ( Self :: Optional ) ,
71
72
"cast" => Some ( Self :: Cast ) ,
72
73
"super" => Some ( Self :: Super ) ,
74
+ "exit" => Some ( Self :: Exit ) ,
73
75
_ => None ,
74
76
}
75
77
}
@@ -94,6 +96,7 @@ impl SpecialExport {
94
96
Self :: CollectionsNamedTuple => matches ! ( m. as_str( ) , "collections" ) ,
95
97
Self :: Enum | Self :: StrEnum | Self :: IntEnum => matches ! ( m. as_str( ) , "enum" ) ,
96
98
Self :: Super => matches ! ( m. as_str( ) , "builtins" ) ,
99
+ Self :: Exit => matches ! ( m. as_str( ) , "sys" ) ,
97
100
}
98
101
}
99
102
Original file line number Diff line number Diff line change @@ -223,6 +223,22 @@ def f(x: str | None):
223
223
assert_type(x, str)
224
224
else:
225
225
assert_type(x, None)
226
+ if not x:
227
+ assert_type(x, str | None)
228
+ else:
229
+ assert_type(x, str)
230
+ "# ,
231
+ ) ;
232
+
233
+ testcase ! (
234
+ test_exit,
235
+ r#"
236
+ from typing import assert_type
237
+ import sys
238
+ def f(x: str | None):
239
+ if not x:
240
+ sys.exit(1)
241
+ assert_type(x, str)
226
242
"# ,
227
243
) ;
228
244
You can’t perform that action at this time.
0 commit comments